Skip to content

Commit 221263d

Browse files
jekhormhugent
authored andcommitted
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>
1 parent 381efba commit 221263d

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

src/core/qgsclipper.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ const unsigned char* QgsClipper::clippedLineWKB( const unsigned char* wkb, const
4949
double p1x_c, p1y_c; //clipped end coordinates
5050
double lastClipX = 0.0, lastClipY = 0.0; //last successfully clipped coords
5151

52-
line.reserve( nPoints + 1 );
5352
line.clear();
53+
line.reserve( nPoints + 1 );
5454

5555
for ( unsigned int i = 0; i < nPoints; ++i )
5656
{

src/core/qgsclipper.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -179,11 +179,11 @@ inline void QgsClipper::trimPolygon( QPolygonF& pts, const QgsRectangle& clipRec
179179
tmpPts.reserve( pts.size() );
180180

181181
trimPolygonToBoundary( pts, tmpPts, clipRect, XMax, clipRect.xMaximum() );
182-
pts.clear();
182+
pts.resize( 0 );
183183
trimPolygonToBoundary( tmpPts, pts, clipRect, YMax, clipRect.yMaximum() );
184-
tmpPts.clear();
184+
tmpPts.resize( 0 );
185185
trimPolygonToBoundary( pts, tmpPts, clipRect, XMin, clipRect.xMinimum() );
186-
pts.clear();
186+
pts.resize( 0 );
187187
trimPolygonToBoundary( tmpPts, pts, clipRect, YMin, clipRect.yMinimum() );
188188
}
189189

0 commit comments

Comments
 (0)