Skip to content
Permalink
Browse files

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.
  • Loading branch information
nyalldawson committed Nov 14, 2017
1 parent 0c35dde commit 507a93c69b22168b40ff92bb8622705e1131bb4a
@@ -45,14 +45,12 @@ bool QgsCurve::isRing() const

QgsCoordinateSequence QgsCurve::coordinateSequence() const
{
if ( !mCoordinateSequence.isEmpty() )
return mCoordinateSequence;
QgsCoordinateSequence sequence;
sequence.append( QgsRingSequence() );
sequence.back().append( QgsPointSequence() );
points( sequence.back().back() );

mCoordinateSequence.append( QgsRingSequence() );
mCoordinateSequence.back().append( QgsPointSequence() );
points( mCoordinateSequence.back().back() );

return mCoordinateSequence;
return sequence;
}

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

@@ -203,7 +203,6 @@ class CORE_EXPORT QgsCurve: public QgsAbstractGeometry
private:

mutable QgsRectangle mBoundingBox;
mutable QgsCoordinateSequence mCoordinateSequence;
};

#endif // QGSCURVEV2_H
@@ -724,32 +724,27 @@ void QgsCurvePolygon::transform( const QTransform &t )

QgsCoordinateSequence QgsCurvePolygon::coordinateSequence() const
{
if ( !mCoordinateSequence.isEmpty() )
return mCoordinateSequence;

mCoordinateSequence.append( QgsRingSequence() );
QgsCoordinateSequence sequence;
sequence.append( QgsRingSequence() );

if ( mExteriorRing )
{
mCoordinateSequence.back().append( QgsPointSequence() );
mExteriorRing->points( mCoordinateSequence.back().back() );
sequence.back().append( QgsPointSequence() );
mExteriorRing->points( sequence.back().back() );
}

QList<QgsCurve *>::const_iterator it = mInteriorRings.constBegin();
for ( ; it != mInteriorRings.constEnd(); ++it )
{
mCoordinateSequence.back().append( QgsPointSequence() );
( *it )->points( mCoordinateSequence.back().back() );
sequence.back().append( QgsPointSequence() );
( *it )->points( sequence.back().back() );
}

return mCoordinateSequence;
return sequence;
}

int QgsCurvePolygon::nCoordinates() const
{
if ( !mCoordinateSequence.isEmpty() )
return QgsAbstractGeometry::nCoordinates();

int count = 0;

if ( mExteriorRing )
@@ -421,15 +421,12 @@ QgsRectangle QgsGeometryCollection::calculateBoundingBox() const
void QgsGeometryCollection::clearCache() const
{
mBoundingBox = QgsRectangle();
mCoordinateSequence.clear();
QgsAbstractGeometry::clearCache();
}

QgsCoordinateSequence QgsGeometryCollection::coordinateSequence() const
{
if ( !mCoordinateSequence.isEmpty() )
return mCoordinateSequence;

QgsCoordinateSequence sequence;
QVector< QgsAbstractGeometry * >::const_iterator geomIt = mGeometries.constBegin();
for ( ; geomIt != mGeometries.constEnd(); ++geomIt )
{
@@ -438,18 +435,15 @@ QgsCoordinateSequence QgsGeometryCollection::coordinateSequence() const
QgsCoordinateSequence::const_iterator cIt = geomCoords.constBegin();
for ( ; cIt != geomCoords.constEnd(); ++cIt )
{
mCoordinateSequence.push_back( *cIt );
sequence.push_back( *cIt );
}
}

return mCoordinateSequence;
return sequence;
}

int QgsGeometryCollection::nCoordinates() const
{
if ( !mCoordinateSequence.isEmpty() )
return QgsAbstractGeometry::nCoordinates();

int count = 0;

QVector< QgsAbstractGeometry * >::const_iterator geomIt = mGeometries.constBegin();
@@ -185,7 +185,6 @@ class CORE_EXPORT QgsGeometryCollection: public QgsAbstractGeometry
private:

mutable QgsRectangle mBoundingBox;
mutable QgsCoordinateSequence mCoordinateSequence;
};

// clazy:excludeall=qstring-allocations
@@ -75,9 +75,8 @@ class CORE_EXPORT QgsSurface: public QgsAbstractGeometry
#endif
protected:

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

mutable QgsCoordinateSequence mCoordinateSequence;
mutable QgsRectangle mBoundingBox;
};

0 comments on commit 507a93c

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