Skip to content
Permalink
Browse files

Properly reserve place for arrays in line and polygon clipping routines

A QVector::clear() method completely reinitializes the object. Calling
a QVector::reserve() before clear() is useless and causes big overhead at
array append operations.

Give ~6% perfomance gain.

Signed-off-by: Yauhen Kharuzhy <jekhor@gmail.com>
  • Loading branch information
jekhor authored and mhugent committed Dec 8, 2013
1 parent 381efba commit 221263db95fc1c293a7d35c4760033934abb3e1b
Showing with 4 additions and 4 deletions.
  1. +1 −1 src/core/qgsclipper.cpp
  2. +3 −3 src/core/qgsclipper.h
@@ -49,8 +49,8 @@ const unsigned char* QgsClipper::clippedLineWKB( const unsigned char* wkb, const
double p1x_c, p1y_c; //clipped end coordinates
double lastClipX = 0.0, lastClipY = 0.0; //last successfully clipped coords

line.reserve( nPoints + 1 );
line.clear();
line.reserve( nPoints + 1 );

for ( unsigned int i = 0; i < nPoints; ++i )
{
@@ -179,11 +179,11 @@ inline void QgsClipper::trimPolygon( QPolygonF& pts, const QgsRectangle& clipRec
tmpPts.reserve( pts.size() );

trimPolygonToBoundary( pts, tmpPts, clipRect, XMax, clipRect.xMaximum() );
pts.clear();
pts.resize( 0 );
trimPolygonToBoundary( tmpPts, pts, clipRect, YMax, clipRect.yMaximum() );
tmpPts.clear();
tmpPts.resize( 0 );
trimPolygonToBoundary( pts, tmpPts, clipRect, XMin, clipRect.xMinimum() );
pts.clear();
pts.resize( 0 );
trimPolygonToBoundary( tmpPts, pts, clipRect, YMin, clipRect.yMinimum() );
}

0 comments on commit 221263d

Please sign in to comment.
You can’t perform that action at this time.