Skip to content

Commit

Permalink
Merge pull request #6300 from nyalldawson/opts
Browse files Browse the repository at this point in the history
Misc optimizations for everything
  • Loading branch information
nyalldawson committed Feb 12, 2018
2 parents 2cbcf74 + 24fb28f commit 46d7a42
Show file tree
Hide file tree
Showing 35 changed files with 181 additions and 92 deletions.
4 changes: 2 additions & 2 deletions python/core/geometry/qgsabstractgeometry.sip.in
Expand Up @@ -596,8 +596,6 @@ Returns Java-style iterator for traversal of vertices of the geometry
.. versionadded:: 3.0
%End

protected:

virtual QgsAbstractGeometry *createEmptyWithSameType() const = 0 /Factory/;
%Docstring
Creates a new geometry with the same class and same WKB type as the original and transfers ownership.
Expand All @@ -612,6 +610,8 @@ To create it, the geometry is default constructed and then the WKB is changed.
Not available in Python bindings
%End

protected:

virtual bool hasChildGeometries() const;
%Docstring
Returns whether the geometry has any child geometries (false for point / curve, true otherwise)
Expand Down
4 changes: 3 additions & 1 deletion python/core/geometry/qgscircularstring.sip.in
Expand Up @@ -127,9 +127,11 @@ Sets the circular string's points
virtual double yAt( int index ) const;


protected:
virtual QgsCircularString *createEmptyWithSameType() const /Factory/;


protected:

virtual QgsRectangle calculateBoundingBox() const;


Expand Down
5 changes: 3 additions & 2 deletions python/core/geometry/qgscompoundcurve.sip.in
Expand Up @@ -160,12 +160,13 @@ Appends first point if not already closed.
virtual double yAt( int index ) const;


virtual QgsCompoundCurve *createEmptyWithSameType() const /Factory/;


protected:

virtual QgsRectangle calculateBoundingBox() const;

virtual QgsCompoundCurve *createEmptyWithSameType() const /Factory/;


};

Expand Down
5 changes: 4 additions & 1 deletion python/core/geometry/qgscurvepolygon.sip.in
Expand Up @@ -198,9 +198,12 @@ Returns approximate rotation angle for a vertex. Usually average angle between a

virtual QgsCurvePolygon *toCurveType() const /Factory/;

protected:

virtual QgsCurvePolygon *createEmptyWithSameType() const /Factory/;


protected:

virtual int childCount() const;

virtual QgsAbstractGeometry *childGeometry( int index ) const;
Expand Down
3 changes: 2 additions & 1 deletion python/core/geometry/qgsgeometrycollection.sip.in
Expand Up @@ -176,9 +176,10 @@ Returns a geometry without curves. Caller takes ownership



protected:
virtual QgsGeometryCollection *createEmptyWithSameType() const /Factory/;


protected:
virtual int childCount() const;

virtual QgsAbstractGeometry *childGeometry( int index ) const;
Expand Down
5 changes: 4 additions & 1 deletion python/core/geometry/qgslinestring.sip.in
Expand Up @@ -290,9 +290,12 @@ of the curve.
virtual bool convertTo( QgsWkbTypes::Type type );


protected:

virtual QgsLineString *createEmptyWithSameType() const /Factory/;


protected:

virtual QgsRectangle calculateBoundingBox() const;


Expand Down
3 changes: 1 addition & 2 deletions python/core/geometry/qgsmulticurve.sip.in
Expand Up @@ -53,11 +53,10 @@ Returns a copy of the multi curve, where each component curve has had its line d



protected:

virtual QgsMultiCurve *createEmptyWithSameType() const /Factory/;



};


Expand Down
5 changes: 4 additions & 1 deletion python/core/geometry/qgsmultilinestring.sip.in
Expand Up @@ -49,9 +49,12 @@ Returns the geometry converted to the more generic curve type :py:class:`QgsMult
:return: the converted geometry. Caller takes ownership*
%End

protected:

virtual QgsMultiLineString *createEmptyWithSameType() const /Factory/;


protected:

virtual bool wktOmitChildType() const;

};
Expand Down
5 changes: 4 additions & 1 deletion python/core/geometry/qgsmultipoint.sip.in
Expand Up @@ -51,9 +51,12 @@ class QgsMultiPoint: QgsGeometryCollection
virtual double segmentLength( QgsVertexId startVertex ) const;


protected:

virtual QgsMultiPoint *createEmptyWithSameType() const /Factory/;


protected:

virtual bool wktOmitChildType() const;


Expand Down
4 changes: 3 additions & 1 deletion python/core/geometry/qgsmultipolygon.sip.in
Expand Up @@ -51,9 +51,11 @@ Returns the geometry converted to the more generic curve type :py:class:`QgsMult
virtual QgsAbstractGeometry *boundary() const /Factory/;


protected:
virtual QgsMultiPolygon *createEmptyWithSameType() const /Factory/;


protected:

virtual bool wktOmitChildType() const;

};
Expand Down
1 change: 0 additions & 1 deletion python/core/geometry/qgsmultisurface.sip.in
Expand Up @@ -45,7 +45,6 @@ class QgsMultiSurface: QgsGeometryCollection



protected:
virtual QgsMultiSurface *createEmptyWithSameType() const /Factory/;


Expand Down
4 changes: 3 additions & 1 deletion python/core/geometry/qgspoint.sip.in
Expand Up @@ -419,9 +419,11 @@ Angle undefined. Always returns 0.0



protected:
virtual QgsPoint *createEmptyWithSameType() const /Factory/;


protected:

virtual int childCount() const;

virtual QgsPoint childPoint( int index ) const;
Expand Down
4 changes: 2 additions & 2 deletions python/core/geometry/qgspolygon.sip.in
Expand Up @@ -62,11 +62,11 @@ negative if the point lies outside the polygon.
%End


protected:

virtual QgsPolygon *createEmptyWithSameType() const /Factory/;


protected:


};
/************************************************************************
Expand Down
5 changes: 4 additions & 1 deletion python/core/geometry/qgsrectangle.sip.in
Expand Up @@ -26,7 +26,10 @@ Examples are storing a layer extent or the current view extent of a map
#include "qgsrectangle.h"
%End
public:
QgsRectangle( double xMin = 0, double yMin = 0, double xMax = 0, double yMax = 0 );

QgsRectangle(); // optimised constructor for null rectangle - no need to call normalize here

explicit QgsRectangle( double xMin, double yMin = 0, double xMax = 0, double yMax = 0 );
%Docstring
Constructor
%End
Expand Down
3 changes: 1 addition & 2 deletions python/core/geometry/qgstriangle.sip.in
Expand Up @@ -425,11 +425,10 @@ Example:
%End


protected:

virtual QgsTriangle *createEmptyWithSameType() const /Factory/;



};
/************************************************************************
* This file has been generated automatically from *
Expand Down
4 changes: 2 additions & 2 deletions src/core/geometry/qgsabstractgeometry.h
Expand Up @@ -617,8 +617,6 @@ class CORE_EXPORT QgsAbstractGeometry
*/
QgsVertexIterator vertices() const;

protected:

/**
* Creates a new geometry with the same class and same WKB type as the original and transfers ownership.
* To create it, the geometry is default constructed and then the WKB is changed.
Expand All @@ -628,6 +626,8 @@ class CORE_EXPORT QgsAbstractGeometry
*/
virtual QgsAbstractGeometry *createEmptyWithSameType() const = 0 SIP_FACTORY;

protected:

/**
* Returns whether the geometry has any child geometries (false for point / curve, true otherwise)
* \note used for vertex_iterator implementation
Expand Down
4 changes: 3 additions & 1 deletion src/core/geometry/qgscircularstring.h
Expand Up @@ -113,8 +113,10 @@ class CORE_EXPORT QgsCircularString: public QgsCurve
}
#endif

protected:
QgsCircularString *createEmptyWithSameType() const override SIP_FACTORY;

protected:

QgsRectangle calculateBoundingBox() const override;

private:
Expand Down
3 changes: 2 additions & 1 deletion src/core/geometry/qgscompoundcurve.h
Expand Up @@ -142,10 +142,11 @@ class CORE_EXPORT QgsCompoundCurve: public QgsCurve
}
#endif

QgsCompoundCurve *createEmptyWithSameType() const override SIP_FACTORY;

protected:

QgsRectangle calculateBoundingBox() const override;
QgsCompoundCurve *createEmptyWithSameType() const override SIP_FACTORY;

private:
QVector< QgsCurve * > mCurves;
Expand Down
5 changes: 4 additions & 1 deletion src/core/geometry/qgscurvepolygon.h
Expand Up @@ -175,8 +175,11 @@ class CORE_EXPORT QgsCurvePolygon: public QgsSurface
return nullptr;
}
#endif
protected:

QgsCurvePolygon *createEmptyWithSameType() const override SIP_FACTORY;

protected:

int childCount() const override;
QgsAbstractGeometry *childGeometry( int index ) const override;

Expand Down
37 changes: 24 additions & 13 deletions src/core/geometry/qgsgeometry.cpp
Expand Up @@ -223,17 +223,20 @@ QgsGeometry QgsGeometry::fromMultiPolygonXY( const QgsMultiPolygonXY &multipoly

QgsGeometry QgsGeometry::fromRect( const QgsRectangle &rect )
{
QgsPolylineXY ring;
ring.append( QgsPointXY( rect.xMinimum(), rect.yMinimum() ) );
ring.append( QgsPointXY( rect.xMaximum(), rect.yMinimum() ) );
ring.append( QgsPointXY( rect.xMaximum(), rect.yMaximum() ) );
ring.append( QgsPointXY( rect.xMinimum(), rect.yMaximum() ) );
ring.append( QgsPointXY( rect.xMinimum(), rect.yMinimum() ) );

QgsPolygonXY polygon;
polygon.append( ring );

return fromPolygonXY( polygon );
std::unique_ptr< QgsLineString > ext = qgis::make_unique< QgsLineString >(
QVector< double >() << rect.xMinimum()
<< rect.xMaximum()
<< rect.xMaximum()
<< rect.xMinimum()
<< rect.xMinimum(),
QVector< double >() << rect.yMinimum()
<< rect.yMinimum()
<< rect.yMaximum()
<< rect.yMaximum()
<< rect.yMinimum() );
std::unique_ptr< QgsPolygon > polygon = qgis::make_unique< QgsPolygon >();
polygon->setExteriorRing( ext.release() );
return QgsGeometry( std::move( polygon ) );
}

QgsGeometry QgsGeometry::collectGeometry( const QVector< QgsGeometry > &geometries )
Expand Down Expand Up @@ -1258,8 +1261,16 @@ bool QgsGeometry::convertToMultiType()
return false;
}

multiGeom->addGeometry( d->geometry->clone() );
reset( std::move( geom ) );
//try to avoid cloning existing geometry whenever we can

//want to see a magic trick?... gather round kiddies...
detach(); // maybe a clone, hopefully not if we're the only ref to the private data
// now we cheat a bit and steal the private geometry and add it direct to the multigeom
// we can do this because we're the only ref to this geometry, guaranteed by the detach call above
multiGeom->addGeometry( d->geometry.release() );
// and replace it with the multi geometry.
// TADA! a clone free conversion in some cases
d->geometry = std::move( geom );
return true;
}

Expand Down
3 changes: 2 additions & 1 deletion src/core/geometry/qgsgeometrycollection.h
Expand Up @@ -159,8 +159,9 @@ class CORE_EXPORT QgsGeometryCollection: public QgsAbstractGeometry
}
#endif

protected:
QgsGeometryCollection *createEmptyWithSameType() const override SIP_FACTORY;

protected:
int childCount() const override;
QgsAbstractGeometry *childGeometry( int index ) const override;

Expand Down
5 changes: 4 additions & 1 deletion src/core/geometry/qgslinestring.h
Expand Up @@ -253,8 +253,11 @@ class CORE_EXPORT QgsLineString: public QgsCurve
return nullptr;
}
#endif
protected:

QgsLineString *createEmptyWithSameType() const override SIP_FACTORY;

protected:

QgsRectangle calculateBoundingBox() const override;

private:
Expand Down
3 changes: 1 addition & 2 deletions src/core/geometry/qgsmulticurve.h
Expand Up @@ -71,10 +71,9 @@ class CORE_EXPORT QgsMultiCurve: public QgsGeometryCollection
}
#endif

protected:

QgsMultiCurve *createEmptyWithSameType() const override SIP_FACTORY;


};

// clazy:excludeall=qstring-allocations
Expand Down
5 changes: 4 additions & 1 deletion src/core/geometry/qgsmultilinestring.h
Expand Up @@ -62,8 +62,11 @@ class CORE_EXPORT QgsMultiLineString: public QgsMultiCurve
return nullptr;
}
#endif
protected:

QgsMultiLineString *createEmptyWithSameType() const override SIP_FACTORY;

protected:

bool wktOmitChildType() const override;
};

Expand Down
5 changes: 4 additions & 1 deletion src/core/geometry/qgsmultipoint.h
Expand Up @@ -62,8 +62,11 @@ class CORE_EXPORT QgsMultiPoint: public QgsGeometryCollection
return nullptr;
}
#endif
protected:

QgsMultiPoint *createEmptyWithSameType() const override SIP_FACTORY;

protected:

bool wktOmitChildType() const override;

};
Expand Down
4 changes: 3 additions & 1 deletion src/core/geometry/qgsmultipolygon.h
Expand Up @@ -63,8 +63,10 @@ class CORE_EXPORT QgsMultiPolygon: public QgsMultiSurface
}
#endif

protected:
QgsMultiPolygon *createEmptyWithSameType() const override SIP_FACTORY;

protected:

bool wktOmitChildType() const override;
};

Expand Down
1 change: 0 additions & 1 deletion src/core/geometry/qgsmultisurface.h
Expand Up @@ -65,7 +65,6 @@ class CORE_EXPORT QgsMultiSurface: public QgsGeometryCollection
}
#endif

protected:
QgsMultiSurface *createEmptyWithSameType() const override SIP_FACTORY;

};
Expand Down

0 comments on commit 46d7a42

Please sign in to comment.