Skip to content

Commit

Permalink
Fix some clazy container-inside-loop warnings
Browse files Browse the repository at this point in the history
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 8a742e9
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
3 changes: 2 additions & 1 deletion src/core/qgsogcutils.cpp
Expand Up @@ -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 )
Expand Down
12 changes: 8 additions & 4 deletions src/core/symbology-ng/qgsinvertedpolygonrenderer.cpp
Expand Up @@ -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 )
{
Expand All @@ -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 )
{
Expand Down Expand Up @@ -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 );
}
}
}
Expand Down

0 comments on commit 8a742e9

Please sign in to comment.