Skip to content

Commit

Permalink
Avoid cloning in QgsGeometry::convertToMultiType where possible
Browse files Browse the repository at this point in the history
Refs #17809
  • Loading branch information
nyalldawson committed Feb 11, 2018
1 parent c7e257e commit db12f00
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/core/geometry/qgsgeometry.cpp
Expand Up @@ -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;
}

Expand Down

0 comments on commit db12f00

Please sign in to comment.