Skip to content

Commit 507a93c

Browse files
committedNov 14, 2017
Drop the cached coordinate sequence from abstract geometries
This cache was added to speed up expensive QgsAbstractGeometry::coordinateSequence calls, when we were relying on coordinateSequence() for a whole bunch of stuff like counting the number of points in a geometry. Now it's used almost no-where in the code, so this cache is unlikely to get filled and just makes geometries more memory heavy than they need to be.
1 parent 0c35dde commit 507a93c

File tree

6 files changed

+16
-33
lines changed

6 files changed

+16
-33
lines changed
 

‎src/core/geometry/qgscurve.cpp

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,12 @@ bool QgsCurve::isRing() const
4545

4646
QgsCoordinateSequence QgsCurve::coordinateSequence() const
4747
{
48-
if ( !mCoordinateSequence.isEmpty() )
49-
return mCoordinateSequence;
48+
QgsCoordinateSequence sequence;
49+
sequence.append( QgsRingSequence() );
50+
sequence.back().append( QgsPointSequence() );
51+
points( sequence.back().back() );
5052

51-
mCoordinateSequence.append( QgsRingSequence() );
52-
mCoordinateSequence.back().append( QgsPointSequence() );
53-
points( mCoordinateSequence.back().back() );
54-
55-
return mCoordinateSequence;
53+
return sequence;
5654
}
5755

5856
bool QgsCurve::nextVertex( QgsVertexId &id, QgsPoint &vertex ) const
@@ -191,7 +189,6 @@ QPolygonF QgsCurve::asQPolygonF() const
191189
void QgsCurve::clearCache() const
192190
{
193191
mBoundingBox = QgsRectangle();
194-
mCoordinateSequence.clear();
195192
QgsAbstractGeometry::clearCache();
196193
}
197194

‎src/core/geometry/qgscurve.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,6 @@ class CORE_EXPORT QgsCurve: public QgsAbstractGeometry
203203
private:
204204

205205
mutable QgsRectangle mBoundingBox;
206-
mutable QgsCoordinateSequence mCoordinateSequence;
207206
};
208207

209208
#endif // QGSCURVEV2_H

‎src/core/geometry/qgscurvepolygon.cpp

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -724,32 +724,27 @@ void QgsCurvePolygon::transform( const QTransform &t )
724724

725725
QgsCoordinateSequence QgsCurvePolygon::coordinateSequence() const
726726
{
727-
if ( !mCoordinateSequence.isEmpty() )
728-
return mCoordinateSequence;
729-
730-
mCoordinateSequence.append( QgsRingSequence() );
727+
QgsCoordinateSequence sequence;
728+
sequence.append( QgsRingSequence() );
731729

732730
if ( mExteriorRing )
733731
{
734-
mCoordinateSequence.back().append( QgsPointSequence() );
735-
mExteriorRing->points( mCoordinateSequence.back().back() );
732+
sequence.back().append( QgsPointSequence() );
733+
mExteriorRing->points( sequence.back().back() );
736734
}
737735

738736
QList<QgsCurve *>::const_iterator it = mInteriorRings.constBegin();
739737
for ( ; it != mInteriorRings.constEnd(); ++it )
740738
{
741-
mCoordinateSequence.back().append( QgsPointSequence() );
742-
( *it )->points( mCoordinateSequence.back().back() );
739+
sequence.back().append( QgsPointSequence() );
740+
( *it )->points( sequence.back().back() );
743741
}
744742

745-
return mCoordinateSequence;
743+
return sequence;
746744
}
747745

748746
int QgsCurvePolygon::nCoordinates() const
749747
{
750-
if ( !mCoordinateSequence.isEmpty() )
751-
return QgsAbstractGeometry::nCoordinates();
752-
753748
int count = 0;
754749

755750
if ( mExteriorRing )

‎src/core/geometry/qgsgeometrycollection.cpp

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -421,15 +421,12 @@ QgsRectangle QgsGeometryCollection::calculateBoundingBox() const
421421
void QgsGeometryCollection::clearCache() const
422422
{
423423
mBoundingBox = QgsRectangle();
424-
mCoordinateSequence.clear();
425424
QgsAbstractGeometry::clearCache();
426425
}
427426

428427
QgsCoordinateSequence QgsGeometryCollection::coordinateSequence() const
429428
{
430-
if ( !mCoordinateSequence.isEmpty() )
431-
return mCoordinateSequence;
432-
429+
QgsCoordinateSequence sequence;
433430
QVector< QgsAbstractGeometry * >::const_iterator geomIt = mGeometries.constBegin();
434431
for ( ; geomIt != mGeometries.constEnd(); ++geomIt )
435432
{
@@ -438,18 +435,15 @@ QgsCoordinateSequence QgsGeometryCollection::coordinateSequence() const
438435
QgsCoordinateSequence::const_iterator cIt = geomCoords.constBegin();
439436
for ( ; cIt != geomCoords.constEnd(); ++cIt )
440437
{
441-
mCoordinateSequence.push_back( *cIt );
438+
sequence.push_back( *cIt );
442439
}
443440
}
444441

445-
return mCoordinateSequence;
442+
return sequence;
446443
}
447444

448445
int QgsGeometryCollection::nCoordinates() const
449446
{
450-
if ( !mCoordinateSequence.isEmpty() )
451-
return QgsAbstractGeometry::nCoordinates();
452-
453447
int count = 0;
454448

455449
QVector< QgsAbstractGeometry * >::const_iterator geomIt = mGeometries.constBegin();

‎src/core/geometry/qgsgeometrycollection.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,6 @@ class CORE_EXPORT QgsGeometryCollection: public QgsAbstractGeometry
185185
private:
186186

187187
mutable QgsRectangle mBoundingBox;
188-
mutable QgsCoordinateSequence mCoordinateSequence;
189188
};
190189

191190
// clazy:excludeall=qstring-allocations

‎src/core/geometry/qgssurface.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,8 @@ class CORE_EXPORT QgsSurface: public QgsAbstractGeometry
7575
#endif
7676
protected:
7777

78-
virtual void clearCache() const override { mBoundingBox = QgsRectangle(); mCoordinateSequence.clear(); QgsAbstractGeometry::clearCache(); }
78+
virtual void clearCache() const override { mBoundingBox = QgsRectangle(); QgsAbstractGeometry::clearCache(); }
7979

80-
mutable QgsCoordinateSequence mCoordinateSequence;
8180
mutable QgsRectangle mBoundingBox;
8281
};
8382

0 commit comments

Comments
 (0)
Please sign in to comment.