[geos-commits] r2734 - trunk/source/geom
svn_geos at osgeo.org
svn_geos at osgeo.org
Mon Nov 23 13:06:38 EST 2009
Author: strk
Date: 2009-11-23 13:06:37 -0500 (Mon, 23 Nov 2009)
New Revision: 2734
Modified:
trunk/source/geom/Geometry.cpp
Log:
Avoid reallocations in Union short-circuit
Modified: trunk/source/geom/Geometry.cpp
===================================================================
--- trunk/source/geom/Geometry.cpp 2009-11-20 19:58:33 UTC (rev 2733)
+++ trunk/source/geom/Geometry.cpp 2009-11-23 18:06:37 UTC (rev 2734)
@@ -563,13 +563,18 @@
{
//cerr<<"SHORTCIRCUITED-UNION engaged"<<endl;
const GeometryCollection *coll;
- size_t ngeoms, i;
+
+ size_t ngeomsThis = getNumGeometries();
+ size_t ngeomsOther = other->getNumGeometries();
+
+ // Allocated for ownership transfer
vector<Geometry *> *v = new vector<Geometry *>();
+ v->reserve(ngeomsThis+ngeomsOther);
+
if ( NULL != (coll = dynamic_cast<const GeometryCollection *>(this)) )
{
- ngeoms = coll->getNumGeometries();
- for (i=0; i<ngeoms; i++)
+ for (size_t i=0; i<ngeomsThis; ++i)
v->push_back(coll->getGeometryN(i)->clone());
} else {
v->push_back(this->clone());
@@ -577,8 +582,7 @@
if ( NULL != (coll = dynamic_cast<const GeometryCollection *>(other)) )
{
- ngeoms = coll->getNumGeometries();
- for (i=0; i<ngeoms; i++)
+ for (size_t i=0; i<ngeomsOther; ++i)
v->push_back(coll->getGeometryN(i)->clone());
} else {
v->push_back(other->clone());
More information about the geos-commits
mailing list