Skip to content
Permalink
Browse files

Avoid cloning in QgsGeometry::convertToMultiType where possible

Refs #17809
  • Loading branch information
nyalldawson committed Feb 11, 2018
1 parent c7e257e commit db12f006d9b35722ed001e0fdac872d737555ffa
Showing with 10 additions and 2 deletions.
  1. +10 −2 src/core/geometry/qgsgeometry.cpp
@@ -1258,8 +1258,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;
}

0 comments on commit db12f00

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