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."
This commit is contained in:
Nyall Dawson 2016-10-24 08:52:51 +10:00
parent bdc39ff659
commit 8a742e9445
2 changed files with 10 additions and 5 deletions

View File

@ -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 )

View File

@ -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 );
}
}
}