Skip to content

Commit

Permalink
Properly reserve place for arrays in line and polygon clipping routines
Browse files Browse the repository at this point in the history
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 9, 2013
1 parent 381efba commit 221263d
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/core/qgsclipper.cpp
Expand Up @@ -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 )
{
Expand Down
6 changes: 3 additions & 3 deletions src/core/qgsclipper.h
Expand Up @@ -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() );
}

Expand Down

0 comments on commit 221263d

Please sign in to comment.