Skip to content

Commit

Permalink
Avoid unnecessary temporary container and double iteration over
Browse files Browse the repository at this point in the history
containers by directly iterating over container itself, rather
then iterating over .keys()/.values()
  • Loading branch information
nyalldawson committed May 15, 2016
1 parent 77c4ed5 commit e25ffc4
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
5 changes: 3 additions & 2 deletions src/core/qgsmaplayerregistry.h
Expand Up @@ -66,9 +66,10 @@ class CORE_EXPORT QgsMapLayerRegistry : public QObject
QVector<T> layers() const
{
QVector<T> layers;
Q_FOREACH ( QgsMapLayer* layer, mMapLayers.values() )
QMap<QString, QgsMapLayer*>::const_iterator layerIt = mMapLayers.constBegin();
for ( ; layerIt != mMapLayers.constEnd(); ++layerIt )
{
T tLayer = qobject_cast<T>( layer );
T tLayer = qobject_cast<T>( layerIt.value() );
if ( tLayer )
{
layers << tLayer;
Expand Down
8 changes: 7 additions & 1 deletion src/core/qgsvectorlayerfeatureiterator.cpp
Expand Up @@ -154,7 +154,13 @@ QgsVectorLayerFeatureIterator::QgsVectorLayerFeatureIterator( QgsVectorLayerFeat
if ( mSource->mHasEditBuffer )
{
mChangedFeaturesRequest = mProviderRequest;
mChangedFeaturesRequest.setFilterFids( mSource->mChangedAttributeValues.keys().toSet() );
QgsFeatureIds changedIds;
QgsChangedAttributesMap::const_iterator attIt = mSource->mChangedAttributeValues.constBegin();
for ( ; attIt != mSource->mChangedAttributeValues.constEnd(); ++attIt )
{
changedIds << attIt.key();
}
mChangedFeaturesRequest.setFilterFids( changedIds );
}

if ( request.filterType() == QgsFeatureRequest::FilterFid )
Expand Down
7 changes: 4 additions & 3 deletions src/providers/ogr/qgsogrprovider.cpp
Expand Up @@ -657,11 +657,12 @@ QStringList QgsOgrProvider::subLayers() const
fCount[wkbUnknown] = 0;
}
bool bIs25D = (( layerGeomType & wkb25DBit ) != 0 );
Q_FOREACH ( OGRwkbGeometryType gType, fCount.keys() )
QMap<OGRwkbGeometryType, int>::const_iterator countIt = fCount.constBegin();
for ( ; countIt != fCount.constEnd(); ++countIt )
{
QString geom = ogrWkbGeometryTypeName(( bIs25D ) ? ( OGRwkbGeometryType )( gType | wkb25DBit ) : gType );
QString geom = ogrWkbGeometryTypeName(( bIs25D ) ? ( OGRwkbGeometryType )( countIt.key() | wkb25DBit ) : countIt.key() );

QString sl = QString( "%1:%2:%3:%4" ).arg( i ).arg( theLayerName ).arg( fCount.value( gType ) ).arg( geom );
QString sl = QString( "%1:%2:%3:%4" ).arg( i ).arg( theLayerName ).arg( fCount.value( countIt.key() ) ).arg( geom );
QgsDebugMsg( "sub layer: " + sl );
mSubLayerList << sl;
}
Expand Down

0 comments on commit e25ffc4

Please sign in to comment.