Skip to content

Commit

Permalink
Misc optimisations suggested by clazy
Browse files Browse the repository at this point in the history
- avoid Q_FOREACH( ..., QMap.values() ) as it allocates an unnecessary
list
- use .endsWith( ... , Qt::CaseInsensitive) instead of
.lower().endsWith( ... ) as it avoids an extra QString allocation
  • Loading branch information
nyalldawson committed Feb 12, 2016
1 parent d0e595f commit c50033b
Show file tree
Hide file tree
Showing 23 changed files with 34 additions and 34 deletions.
2 changes: 1 addition & 1 deletion src/app/main.cpp
Expand Up @@ -1172,7 +1172,7 @@ int main( int argc, char *argv[] )
} }
else else
{ {
Q_FOREACH ( QgsMapLayer *ml, QgsMapLayerRegistry::instance()->mapLayers().values() ) Q_FOREACH ( QgsMapLayer *ml, QgsMapLayerRegistry::instance()->mapLayers() )
{ {
QgsVectorLayer *vl = qobject_cast<QgsVectorLayer *>( ml ); QgsVectorLayer *vl = qobject_cast<QgsVectorLayer *>( ml );
if ( !vl ) if ( !vl )
Expand Down
2 changes: 1 addition & 1 deletion src/app/nodetool/qgsmaptoolnodetool.cpp
Expand Up @@ -67,7 +67,7 @@ void QgsMapToolNodeTool::createTopologyRubberBands()
// Snap vertex // Snap vertex
QMultiMap<double, QgsSnappingResult> snapResults; QMultiMap<double, QgsSnappingResult> snapResults;
vlayer->snapWithContext( vertexEntry->pointV1(), ZERO_TOLERANCE, snapResults, QgsSnapper::SnapToVertex ); vlayer->snapWithContext( vertexEntry->pointV1(), ZERO_TOLERANCE, snapResults, QgsSnapper::SnapToVertex );
Q_FOREACH ( const QgsSnappingResult& snapResult, snapResults.values() ) Q_FOREACH ( const QgsSnappingResult& snapResult, snapResults )
{ {
// Get geometry of snapped feature // Get geometry of snapped feature
QgsFeatureId snapFeatureId = snapResult.snappedAtGeometry; QgsFeatureId snapFeatureId = snapResult.snappedAtGeometry;
Expand Down
4 changes: 2 additions & 2 deletions src/app/qgisapp.cpp
Expand Up @@ -4798,7 +4798,7 @@ bool QgisApp::openLayer( const QString & fileName, bool allowInteractive )
if ( QgsRasterLayer::isValidRasterFileName( fileName ) ) if ( QgsRasterLayer::isValidRasterFileName( fileName ) )
{ {
// open .adf as a directory // open .adf as a directory
if ( fileName.toLower().endsWith( ".adf" ) ) if ( fileName.endsWith( ".adf", Qt::CaseInsensitive ) )
{ {
QString dirName = fileInfo.path(); QString dirName = fileInfo.path();
ok = addRasterLayer( dirName, QFileInfo( dirName ).completeBaseName() ); ok = addRasterLayer( dirName, QFileInfo( dirName ).completeBaseName() );
Expand Down Expand Up @@ -10337,7 +10337,7 @@ QgsRasterLayer* QgisApp::addRasterLayerPrivate(
// XXX ya know QgsRasterLayer can snip out the basename on its own; // XXX ya know QgsRasterLayer can snip out the basename on its own;
// XXX why do we have to pass it in for it? // XXX why do we have to pass it in for it?
// ET : we may not be getting "normal" files here, so we still need the baseName argument // ET : we may not be getting "normal" files here, so we still need the baseName argument
if ( !providerKey.isEmpty() && uri.toLower().endsWith( ".adf" ) ) if ( !providerKey.isEmpty() && uri.endsWith( ".adf", Qt::CaseInsensitive ) )
{ {
QFileInfo fileInfo( uri ); QFileInfo fileInfo( uri );
QString dirName = fileInfo.path(); QString dirName = fileInfo.path();
Expand Down
4 changes: 2 additions & 2 deletions src/app/qgsalignrasterdialog.cpp
Expand Up @@ -36,7 +36,7 @@
static QgsMapLayer* _rasterLayer( const QString& filename ) static QgsMapLayer* _rasterLayer( const QString& filename )
{ {
QMap<QString, QgsMapLayer*> layers = QgsMapLayerRegistry::instance()->mapLayers(); QMap<QString, QgsMapLayer*> layers = QgsMapLayerRegistry::instance()->mapLayers();
Q_FOREACH ( QgsMapLayer* layer, layers.values() ) Q_FOREACH ( QgsMapLayer* layer, layers )
{ {
if ( layer->type() == QgsMapLayer::RasterLayer && layer->source() == filename ) if ( layer->type() == QgsMapLayer::RasterLayer && layer->source() == filename )
return layer; return layer;
Expand Down Expand Up @@ -457,7 +457,7 @@ void QgsAlignRasterLayerConfigDialog::browseOutputFilename()
if ( !fileName.isEmpty() ) if ( !fileName.isEmpty() )
{ {
// ensure the user never ommited the extension from the file name // ensure the user never ommited the extension from the file name
if ( !fileName.toLower().endsWith( ".tif" ) && !fileName.toLower().endsWith( ".tiff" ) ) if ( !fileName.endsWith( ".tif", Qt::CaseInsensitive ) && !fileName.endsWith( ".tiff", Qt::CaseInsensitive ) )
{ {
fileName += ".tif"; fileName += ".tif";
} }
Expand Down
2 changes: 1 addition & 1 deletion src/app/qgsbookmarks.cpp
Expand Up @@ -326,7 +326,7 @@ void QgsBookmarks::exportToXML()
} }


// ensure the user never ommited the extension from the file name // ensure the user never ommited the extension from the file name
if ( !fileName.toLower().endsWith( ".xml" ) ) if ( !fileName.endsWith( ".xml", Qt::CaseInsensitive ) )
{ {
fileName += ".xml"; fileName += ".xml";
} }
Expand Down
2 changes: 1 addition & 1 deletion src/app/qgsconfigureshortcutsdialog.cpp
Expand Up @@ -107,7 +107,7 @@ void QgsConfigureShortcutsDialog::saveShortcuts()
return; return;


// ensure the user never omitted the extension from the file name // ensure the user never omitted the extension from the file name
if ( !fileName.toLower().endsWith( ".xml" ) ) if ( !fileName.endsWith( ".xml", Qt::CaseInsensitive ) )
{ {
fileName += ".xml"; fileName += ".xml";
} }
Expand Down
2 changes: 1 addition & 1 deletion src/app/qgsnewspatialitelayerdialog.cpp
Expand Up @@ -117,7 +117,7 @@ void QgsNewSpatialiteLayerDialog::on_toolButtonNewDatabase_clicked()
if ( fileName.isEmpty() ) if ( fileName.isEmpty() )
return; return;


if ( !fileName.toLower().endsWith( ".sqlite" ) && !fileName.toLower().endsWith( ".db" ) ) if ( !fileName.endsWith( ".sqlite", Qt::CaseInsensitive ) && !fileName.endsWith( ".db", Qt::CaseInsensitive ) )
{ {
fileName += ".sqlite"; fileName += ".sqlite";
} }
Expand Down
4 changes: 2 additions & 2 deletions src/app/qgsoptions.cpp
Expand Up @@ -2001,7 +2001,7 @@ void QgsOptions::on_pbnExportScales_clicked()
} }


// ensure the user never ommited the extension from the file name // ensure the user never ommited the extension from the file name
if ( !fileName.toLower().endsWith( ".xml" ) ) if ( !fileName.endsWith( ".xml", Qt::CaseInsensitive ) )
{ {
fileName += ".xml"; fileName += ".xml";
} }
Expand Down Expand Up @@ -2160,7 +2160,7 @@ void QgsOptions::on_mButtonExportColors_clicked()
} }


// ensure filename contains extension // ensure filename contains extension
if ( !fileName.toLower().endsWith( ".gpl" ) ) if ( !fileName.endsWith( ".gpl", Qt::CaseInsensitive ) )
{ {
fileName += ".gpl"; fileName += ".gpl";
} }
Expand Down
8 changes: 4 additions & 4 deletions src/app/qgsprojectproperties.cpp
Expand Up @@ -643,7 +643,7 @@ QgsProjectProperties::QgsProjectProperties( QgsMapCanvas* mapCanvas, QWidget *pa
mTabRelations->layout()->addWidget( mRelationManagerDlg ); mTabRelations->layout()->addWidget( mRelationManagerDlg );


QList<QgsVectorLayer*> vectorLayers; QList<QgsVectorLayer*> vectorLayers;
Q_FOREACH ( QgsMapLayer* mapLayer, mapLayers.values() ) Q_FOREACH ( QgsMapLayer* mapLayer, mapLayers )
{ {
if ( QgsMapLayer::VectorLayer == mapLayer->type() ) if ( QgsMapLayer::VectorLayer == mapLayer->type() )
{ {
Expand Down Expand Up @@ -1482,7 +1482,7 @@ void QgsProjectProperties::on_pbnLaunchOWSChecker_clicked()


QStringList duplicateNames, regExpMessages; QStringList duplicateNames, regExpMessages;
QRegExp snRegExp = QgsApplication::shortNameRegExp(); QRegExp snRegExp = QgsApplication::shortNameRegExp();
Q_FOREACH ( QString name, owsNames ) Q_FOREACH ( const QString& name, owsNames )
{ {
if ( !snRegExp.exactMatch( name ) ) if ( !snRegExp.exactMatch( name ) )
regExpMessages << tr( "Use short name for \"%1\"" ).arg( name ); regExpMessages << tr( "Use short name for \"%1\"" ).arg( name );
Expand Down Expand Up @@ -1583,7 +1583,7 @@ void QgsProjectProperties::on_pbnExportScales_clicked()
} }


// ensure the user never ommited the extension from the file name // ensure the user never ommited the extension from the file name
if ( !fileName.toLower().endsWith( ".xml" ) ) if ( !fileName.endsWith( ".xml", Qt::CaseInsensitive ) )
{ {
fileName += ".xml"; fileName += ".xml";
} }
Expand Down Expand Up @@ -2015,7 +2015,7 @@ void QgsProjectProperties::on_mButtonExportColors_clicked()
} }


// ensure filename contains extension // ensure filename contains extension
if ( !fileName.toLower().endsWith( ".gpl" ) ) if ( !fileName.endsWith( ".gpl", Qt::CaseInsensitive ) )
{ {
fileName += ".gpl"; fileName += ".gpl";
} }
Expand Down
2 changes: 1 addition & 1 deletion src/gui/editorwidgets/qgsvaluemapconfigdlg.cpp
Expand Up @@ -111,7 +111,7 @@ void QgsValueMapConfigDlg::removeSelectedButtonPushed()
} }
} }
} }
for ( i = 0; i < rowsToRemove.values().size(); i++ ) for ( i = 0; i < rowsToRemove.size(); i++ )
{ {
tableWidget->removeRow( rowsToRemove.values().at( i ) - removed ); tableWidget->removeRow( rowsToRemove.values().at( i ) - removed );
removed++; removed++;
Expand Down
2 changes: 1 addition & 1 deletion src/gui/qgisgui.cpp
Expand Up @@ -168,7 +168,7 @@ namespace QgisGui
#endif #endif


// Add the file type suffix to the fileName if required // Add the file type suffix to the fileName if required
if ( !ext.isNull() && !outputFileName.toLower().endsWith( '.' + ext.toLower() ) ) if ( !ext.isNull() && !outputFileName.endsWith( '.' + ext.toLower(), Qt::CaseInsensitive ) )
{ {
outputFileName += '.' + ext; outputFileName += '.' + ext;
} }
Expand Down
2 changes: 1 addition & 1 deletion src/gui/qgscolordialog.cpp
Expand Up @@ -572,7 +572,7 @@ void QgsColorDialogV2::exportColors()
} }


// ensure filename contains extension // ensure filename contains extension
if ( !fileName.toLower().endsWith( ".gpl" ) ) if ( !fileName.endsWith( ".gpl", Qt::CaseInsensitive ) )
{ {
fileName += ".gpl"; fileName += ".gpl";
} }
Expand Down
2 changes: 1 addition & 1 deletion src/gui/qgsmanageconnectionsdialog.cpp
Expand Up @@ -99,7 +99,7 @@ void QgsManageConnectionsDialog::doExportImport()
} }


// ensure the user never ommited the extension from the file name // ensure the user never ommited the extension from the file name
if ( !fileName.toLower().endsWith( ".xml" ) ) if ( !fileName.endsWith( ".xml", Qt::CaseInsensitive ) )
{ {
fileName += ".xml"; fileName += ".xml";
} }
Expand Down
2 changes: 1 addition & 1 deletion src/gui/qgsprojectionselector.cpp
Expand Up @@ -172,7 +172,7 @@ QString QgsProjectionSelector::ogcWmsCrsFilterAsSqlExpression( QSet<QString> * c


// iterate through all incoming CRSs // iterate through all incoming CRSs


Q_FOREACH ( const QString& auth_id, crsFilter->values() ) Q_FOREACH ( const QString& auth_id, *crsFilter )
{ {
QStringList parts = auth_id.split( ':' ); QStringList parts = auth_id.split( ':' );


Expand Down
2 changes: 1 addition & 1 deletion src/gui/qgsrasterlayersaveasdialog.cpp
Expand Up @@ -204,7 +204,7 @@ void QgsRasterLayerSaveAsDialog::on_mBrowseButton_clicked()
if ( !fileName.isEmpty() ) if ( !fileName.isEmpty() )
{ {
// ensure the user never ommited the extension from the file name // ensure the user never ommited the extension from the file name
if ( !fileName.toLower().endsWith( ".tif" ) && !fileName.toLower().endsWith( ".tiff" ) ) if ( !fileName.endsWith( ".tif", Qt::CaseInsensitive ) && !fileName.endsWith( ".tiff", Qt::CaseInsensitive ) )
{ {
fileName += ".tif"; fileName += ".tif";
} }
Expand Down
6 changes: 3 additions & 3 deletions src/gui/symbology-ng/qgssmartgroupeditordialog.cpp
Expand Up @@ -106,7 +106,7 @@ void QgsSmartGroupEditorDialog::addCondition()
// enable the remove buttons when 2nd condition is added // enable the remove buttons when 2nd condition is added
if ( mConditionMap.count() == 1 ) if ( mConditionMap.count() == 1 )
{ {
Q_FOREACH ( QgsSmartGroupCondition *condition, mConditionMap.values() ) Q_FOREACH ( QgsSmartGroupCondition *condition, mConditionMap )
{ {
condition->hideRemoveButton( false ); condition->hideRemoveButton( false );
} }
Expand All @@ -128,7 +128,7 @@ void QgsSmartGroupEditorDialog::removeCondition( int id )
// hide the remove button of the last condition when 2nd last is removed // hide the remove button of the last condition when 2nd last is removed
if ( mConditionMap.count() == 2 ) if ( mConditionMap.count() == 2 )
{ {
Q_FOREACH ( QgsSmartGroupCondition* condition, mConditionMap.values() ) Q_FOREACH ( QgsSmartGroupCondition* condition, mConditionMap )
{ {
condition->hideRemoveButton( true ); condition->hideRemoveButton( true );
} }
Expand All @@ -142,7 +142,7 @@ QgsSmartConditionMap QgsSmartGroupEditorDialog::conditionMap()
{ {
QgsSmartConditionMap conditions; QgsSmartConditionMap conditions;


Q_FOREACH ( QgsSmartGroupCondition* condition, mConditionMap.values() ) Q_FOREACH ( QgsSmartGroupCondition* condition, mConditionMap )
{ {
conditions.insert( condition->constraint(), condition->parameter() ); conditions.insert( condition->constraint(), condition->parameter() );
} }
Expand Down
2 changes: 1 addition & 1 deletion src/gui/symbology-ng/qgsstylev2exportimportdialog.cpp
Expand Up @@ -134,7 +134,7 @@ void QgsStyleV2ExportImportDialog::doExportImport()
} }


// ensure the user never ommited the extension from the file name // ensure the user never ommited the extension from the file name
if ( !fileName.toLower().endsWith( ".xml" ) ) if ( !fileName.endsWith( ".xml", Qt::CaseInsensitive ) )
{ {
fileName += ".xml"; fileName += ".xml";
} }
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/dxf2shp_converter/dxf2shpconvertergui.cpp
Expand Up @@ -163,7 +163,7 @@ void dxf2shpConverterGui::getOutputDir()


if ( !s.isEmpty() ) if ( !s.isEmpty() )
{ {
if ( !s.toLower().endsWith( ".shp" ) ) if ( !s.endsWith( ".shp", Qt::CaseInsensitive ) )
{ {
s += ".shp"; s += ".shp";
} }
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/gps_importer/qgsgpsplugin.cpp
Expand Up @@ -174,7 +174,7 @@ void QgsGPSPlugin::createGPX()
tr( "GPS eXchange file" ) + " (*.gpx)" ); tr( "GPS eXchange file" ) + " (*.gpx)" );
if ( !fileName.isEmpty() ) if ( !fileName.isEmpty() )
{ {
if ( !fileName.toLower().endsWith( ".gpx" ) ) if ( !fileName.endsWith( ".gpx", Qt::CaseInsensitive ) )
{ {
fileName += ".gpx"; fileName += ".gpx";
} }
Expand Down
8 changes: 4 additions & 4 deletions src/plugins/gps_importer/qgsgpsplugingui.cpp
Expand Up @@ -116,7 +116,7 @@ void QgsGPSPluginGui::on_buttonBox_accepted()
int featureType = cmbDLFeatureType->currentIndex(); int featureType = cmbDLFeatureType->currentIndex();


QString fileName = leDLOutput->text(); QString fileName = leDLOutput->text();
if ( !fileName.toLower().endsWith( ".gpx" ) ) if ( !fileName.endsWith( ".gpx", Qt::CaseInsensitive ) )
{ {
fileName += ".gpx"; fileName += ".gpx";
} }
Expand Down Expand Up @@ -166,7 +166,7 @@ void QgsGPSPluginGui::on_pbnDLOutput_clicked()
tr( "GPS eXchange format" ) + " (*.gpx)" ); tr( "GPS eXchange format" ) + " (*.gpx)" );
if ( !myFileNameQString.isEmpty() ) if ( !myFileNameQString.isEmpty() )
{ {
if ( !myFileNameQString.toLower().endsWith( ".gpx" ) ) if ( !myFileNameQString.endsWith( ".gpx", Qt::CaseInsensitive ) )
{ {
myFileNameQString += ".gpx"; myFileNameQString += ".gpx";
} }
Expand Down Expand Up @@ -316,7 +316,7 @@ void QgsGPSPluginGui::on_pbnIMPOutput_clicked()
tr( "GPS eXchange format" ) + " (*.gpx)" ); tr( "GPS eXchange format" ) + " (*.gpx)" );
if ( !myFileNameQString.isEmpty() ) if ( !myFileNameQString.isEmpty() )
{ {
if ( !myFileNameQString.toLower().endsWith( ".gpx" ) ) if ( !myFileNameQString.endsWith( ".gpx", Qt::CaseInsensitive ) )
{ {
myFileNameQString += ".gpx"; myFileNameQString += ".gpx";
} }
Expand Down Expand Up @@ -423,7 +423,7 @@ void QgsGPSPluginGui::on_pbnCONVOutput_clicked()
tr( "GPS eXchange format" ) + " (*.gpx)" ); tr( "GPS eXchange format" ) + " (*.gpx)" );
if ( !myFileNameQString.isEmpty() ) if ( !myFileNameQString.isEmpty() )
{ {
if ( !myFileNameQString.toLower().endsWith( ".gpx" ) ) if ( !myFileNameQString.endsWith( ".gpx", Qt::CaseInsensitive ) )
{ {
myFileNameQString += ".gpx"; myFileNameQString += ".gpx";
} }
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/offline_editing/offline_editing_plugin_gui.cpp
Expand Up @@ -117,7 +117,7 @@ void QgsOfflineEditingPluginGui::on_mBrowseButton_clicked()


if ( !fileName.isEmpty() ) if ( !fileName.isEmpty() )
{ {
if ( !fileName.toLower().endsWith( ".sqlite" ) ) if ( !fileName.endsWith( ".sqlite", Qt::CaseInsensitive ) )
{ {
fileName += ".sqlite"; fileName += ".sqlite";
} }
Expand Down
2 changes: 1 addition & 1 deletion src/providers/virtual/qgsvirtuallayersourceselect.cpp
Expand Up @@ -87,7 +87,7 @@ QgsVirtualLayerSourceSelect::QgsVirtualLayerSourceSelect( QWidget* parent, Qt::W
} }


// configure auto completion with table and column names // configure auto completion with table and column names
Q_FOREACH ( QgsMapLayer* l, QgsMapLayerRegistry::instance()->mapLayers().values() ) Q_FOREACH ( QgsMapLayer* l, QgsMapLayerRegistry::instance()->mapLayers() )
{ {
if ( l->type() == QgsMapLayer::VectorLayer ) if ( l->type() == QgsMapLayer::VectorLayer )
{ {
Expand Down
2 changes: 1 addition & 1 deletion tests/src/gui/testprojectionissues.cpp
Expand Up @@ -68,7 +68,7 @@ void TestProjectionIssues::initTestCase()


// Add all layers in registry to the canvas // Add all layers in registry to the canvas
QList<QgsMapCanvasLayer> canvasLayers; QList<QgsMapCanvasLayer> canvasLayers;
Q_FOREACH ( QgsMapLayer* layer, QgsMapLayerRegistry::instance()->mapLayers().values() ) Q_FOREACH ( QgsMapLayer* layer, QgsMapLayerRegistry::instance()->mapLayers() )
{ {
canvasLayers.append( QgsMapCanvasLayer( layer ) ); canvasLayers.append( QgsMapCanvasLayer( layer ) );
} }
Expand Down

0 comments on commit c50033b

Please sign in to comment.