Skip to content
Permalink
Browse files

Fix some clazy container-inside-loop warnings

From the clazy docs:

"Finds places defining containers inside loops. Defining them
outside the loop and using resize(0) will save memory allocations."
  • Loading branch information
nyalldawson committed Oct 24, 2016
1 parent bdc39ff commit 8a742e9445ac3b28c1af9b5ab444b9559a34b74b
Showing with 10 additions and 5 deletions.
  1. +2 −1 src/core/qgsogcutils.cpp
  2. +8 −4 src/core/symbology-ng/qgsinvertedpolygonrenderer.cpp
@@ -653,9 +653,10 @@ QgsGeometry QgsOgcUtils::geometryFromGMLMultiPolygon( const QDomElement& geometr
QDomNodeList currentPosList;

QDomNodeList polygonMemberList = geometryElement.elementsByTagNameNS( GML_NAMESPACE, "polygonMember" );
QgsPolygon currentPolygonList;
for ( int i = 0; i < polygonMemberList.size(); ++i )
{
QgsPolygon currentPolygonList;
currentPolygonList.resize( 0 ); // preserve capacity - don't use clear
currentPolygonMemberElement = polygonMemberList.at( i ).toElement();
polygonList = currentPolygonMemberElement.elementsByTagNameNS( GML_NAMESPACE, "Polygon" );
if ( polygonList.size() < 1 )
@@ -259,8 +259,12 @@ void QgsInvertedPolygonRenderer::stopRender( QgsRenderContext& context )
return;
}

QgsMultiPolygon finalMulti; //avoid expensive allocation for list for every feature
QgsPolygon newPoly;

Q_FOREACH ( const CombinedFeature& cit, mFeaturesCategories )
{
finalMulti.resize( 0 ); //preserve capacity - don't use clear!
QgsFeature feat = cit.feature; // just a copy, so that we do not accumulate geometries again
if ( mPreprocessingEnabled )
{
@@ -283,7 +287,7 @@ void QgsInvertedPolygonRenderer::stopRender( QgsRenderContext& context )
//
// No validity check is done, on purpose, it will be very slow and painting
// operations do not need geometries to be valid
QgsMultiPolygon finalMulti;

finalMulti.append( mExtentPolygon );
Q_FOREACH ( const QgsGeometry& geom, cit.geometries )
{
@@ -312,9 +316,9 @@ void QgsInvertedPolygonRenderer::stopRender( QgsRenderContext& context )
// add interior rings as new polygons
for ( int j = 1; j < multi[i].size(); j++ )
{
QgsPolygon new_poly;
new_poly.append( multi[i][j] );
finalMulti.append( new_poly );
newPoly.resize( 0 ); //preserve capacity - don't use clear!
newPoly.append( multi[i][j] );
finalMulti.append( newPoly );
}
}
}

0 comments on commit 8a742e9

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