Skip to content
Permalink
Browse files

Misc optimisations suggested by clazy

- 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 c50033bbaa536f53b46e33fa11810c6802ed6a7f
@@ -1172,7 +1172,7 @@ int main( int argc, char *argv[] )
}
else
{
Q_FOREACH ( QgsMapLayer *ml, QgsMapLayerRegistry::instance()->mapLayers().values() )
Q_FOREACH ( QgsMapLayer *ml, QgsMapLayerRegistry::instance()->mapLayers() )
{
QgsVectorLayer *vl = qobject_cast<QgsVectorLayer *>( ml );
if ( !vl )
@@ -67,7 +67,7 @@ void QgsMapToolNodeTool::createTopologyRubberBands()
// Snap vertex
QMultiMap<double, QgsSnappingResult> snapResults;
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
QgsFeatureId snapFeatureId = snapResult.snappedAtGeometry;
@@ -4798,7 +4798,7 @@ bool QgisApp::openLayer( const QString & fileName, bool allowInteractive )
if ( QgsRasterLayer::isValidRasterFileName( fileName ) )
{
// open .adf as a directory
if ( fileName.toLower().endsWith( ".adf" ) )
if ( fileName.endsWith( ".adf", Qt::CaseInsensitive ) )
{
QString dirName = fileInfo.path();
ok = addRasterLayer( dirName, QFileInfo( dirName ).completeBaseName() );
@@ -10337,7 +10337,7 @@ QgsRasterLayer* QgisApp::addRasterLayerPrivate(
// XXX ya know QgsRasterLayer can snip out the basename on its own;
// 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
if ( !providerKey.isEmpty() && uri.toLower().endsWith( ".adf" ) )
if ( !providerKey.isEmpty() && uri.endsWith( ".adf", Qt::CaseInsensitive ) )
{
QFileInfo fileInfo( uri );
QString dirName = fileInfo.path();
@@ -36,7 +36,7 @@
static QgsMapLayer* _rasterLayer( const QString& filename )
{
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 )
return layer;
@@ -457,7 +457,7 @@ void QgsAlignRasterLayerConfigDialog::browseOutputFilename()
if ( !fileName.isEmpty() )
{
// 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";
}
@@ -326,7 +326,7 @@ void QgsBookmarks::exportToXML()
}

// ensure the user never ommited the extension from the file name
if ( !fileName.toLower().endsWith( ".xml" ) )
if ( !fileName.endsWith( ".xml", Qt::CaseInsensitive ) )
{
fileName += ".xml";
}
@@ -107,7 +107,7 @@ void QgsConfigureShortcutsDialog::saveShortcuts()
return;

// ensure the user never omitted the extension from the file name
if ( !fileName.toLower().endsWith( ".xml" ) )
if ( !fileName.endsWith( ".xml", Qt::CaseInsensitive ) )
{
fileName += ".xml";
}
@@ -117,7 +117,7 @@ void QgsNewSpatialiteLayerDialog::on_toolButtonNewDatabase_clicked()
if ( fileName.isEmpty() )
return;

if ( !fileName.toLower().endsWith( ".sqlite" ) && !fileName.toLower().endsWith( ".db" ) )
if ( !fileName.endsWith( ".sqlite", Qt::CaseInsensitive ) && !fileName.endsWith( ".db", Qt::CaseInsensitive ) )
{
fileName += ".sqlite";
}
@@ -2001,7 +2001,7 @@ void QgsOptions::on_pbnExportScales_clicked()
}

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

// ensure filename contains extension
if ( !fileName.toLower().endsWith( ".gpl" ) )
if ( !fileName.endsWith( ".gpl", Qt::CaseInsensitive ) )
{
fileName += ".gpl";
}
@@ -643,7 +643,7 @@ QgsProjectProperties::QgsProjectProperties( QgsMapCanvas* mapCanvas, QWidget *pa
mTabRelations->layout()->addWidget( mRelationManagerDlg );

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

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

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

// ensure filename contains extension
if ( !fileName.toLower().endsWith( ".gpl" ) )
if ( !fileName.endsWith( ".gpl", Qt::CaseInsensitive ) )
{
fileName += ".gpl";
}
@@ -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 );
removed++;
@@ -168,7 +168,7 @@ namespace QgisGui
#endif

// 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;
}
@@ -572,7 +572,7 @@ void QgsColorDialogV2::exportColors()
}

// ensure filename contains extension
if ( !fileName.toLower().endsWith( ".gpl" ) )
if ( !fileName.endsWith( ".gpl", Qt::CaseInsensitive ) )
{
fileName += ".gpl";
}
@@ -99,7 +99,7 @@ void QgsManageConnectionsDialog::doExportImport()
}

// ensure the user never ommited the extension from the file name
if ( !fileName.toLower().endsWith( ".xml" ) )
if ( !fileName.endsWith( ".xml", Qt::CaseInsensitive ) )
{
fileName += ".xml";
}
@@ -172,7 +172,7 @@ QString QgsProjectionSelector::ogcWmsCrsFilterAsSqlExpression( QSet<QString> * c

// 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( ':' );

@@ -204,7 +204,7 @@ void QgsRasterLayerSaveAsDialog::on_mBrowseButton_clicked()
if ( !fileName.isEmpty() )
{
// 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";
}
@@ -106,7 +106,7 @@ void QgsSmartGroupEditorDialog::addCondition()
// enable the remove buttons when 2nd condition is added
if ( mConditionMap.count() == 1 )
{
Q_FOREACH ( QgsSmartGroupCondition *condition, mConditionMap.values() )
Q_FOREACH ( QgsSmartGroupCondition *condition, mConditionMap )
{
condition->hideRemoveButton( false );
}
@@ -128,7 +128,7 @@ void QgsSmartGroupEditorDialog::removeCondition( int id )
// hide the remove button of the last condition when 2nd last is removed
if ( mConditionMap.count() == 2 )
{
Q_FOREACH ( QgsSmartGroupCondition* condition, mConditionMap.values() )
Q_FOREACH ( QgsSmartGroupCondition* condition, mConditionMap )
{
condition->hideRemoveButton( true );
}
@@ -142,7 +142,7 @@ QgsSmartConditionMap QgsSmartGroupEditorDialog::conditionMap()
{
QgsSmartConditionMap conditions;

Q_FOREACH ( QgsSmartGroupCondition* condition, mConditionMap.values() )
Q_FOREACH ( QgsSmartGroupCondition* condition, mConditionMap )
{
conditions.insert( condition->constraint(), condition->parameter() );
}
@@ -134,7 +134,7 @@ void QgsStyleV2ExportImportDialog::doExportImport()
}

// ensure the user never ommited the extension from the file name
if ( !fileName.toLower().endsWith( ".xml" ) )
if ( !fileName.endsWith( ".xml", Qt::CaseInsensitive ) )
{
fileName += ".xml";
}
@@ -163,7 +163,7 @@ void dxf2shpConverterGui::getOutputDir()

if ( !s.isEmpty() )
{
if ( !s.toLower().endsWith( ".shp" ) )
if ( !s.endsWith( ".shp", Qt::CaseInsensitive ) )
{
s += ".shp";
}
@@ -174,7 +174,7 @@ void QgsGPSPlugin::createGPX()
tr( "GPS eXchange file" ) + " (*.gpx)" );
if ( !fileName.isEmpty() )
{
if ( !fileName.toLower().endsWith( ".gpx" ) )
if ( !fileName.endsWith( ".gpx", Qt::CaseInsensitive ) )
{
fileName += ".gpx";
}
@@ -116,7 +116,7 @@ void QgsGPSPluginGui::on_buttonBox_accepted()
int featureType = cmbDLFeatureType->currentIndex();

QString fileName = leDLOutput->text();
if ( !fileName.toLower().endsWith( ".gpx" ) )
if ( !fileName.endsWith( ".gpx", Qt::CaseInsensitive ) )
{
fileName += ".gpx";
}
@@ -166,7 +166,7 @@ void QgsGPSPluginGui::on_pbnDLOutput_clicked()
tr( "GPS eXchange format" ) + " (*.gpx)" );
if ( !myFileNameQString.isEmpty() )
{
if ( !myFileNameQString.toLower().endsWith( ".gpx" ) )
if ( !myFileNameQString.endsWith( ".gpx", Qt::CaseInsensitive ) )
{
myFileNameQString += ".gpx";
}
@@ -316,7 +316,7 @@ void QgsGPSPluginGui::on_pbnIMPOutput_clicked()
tr( "GPS eXchange format" ) + " (*.gpx)" );
if ( !myFileNameQString.isEmpty() )
{
if ( !myFileNameQString.toLower().endsWith( ".gpx" ) )
if ( !myFileNameQString.endsWith( ".gpx", Qt::CaseInsensitive ) )
{
myFileNameQString += ".gpx";
}
@@ -423,7 +423,7 @@ void QgsGPSPluginGui::on_pbnCONVOutput_clicked()
tr( "GPS eXchange format" ) + " (*.gpx)" );
if ( !myFileNameQString.isEmpty() )
{
if ( !myFileNameQString.toLower().endsWith( ".gpx" ) )
if ( !myFileNameQString.endsWith( ".gpx", Qt::CaseInsensitive ) )
{
myFileNameQString += ".gpx";
}
@@ -117,7 +117,7 @@ void QgsOfflineEditingPluginGui::on_mBrowseButton_clicked()

if ( !fileName.isEmpty() )
{
if ( !fileName.toLower().endsWith( ".sqlite" ) )
if ( !fileName.endsWith( ".sqlite", Qt::CaseInsensitive ) )
{
fileName += ".sqlite";
}
@@ -87,7 +87,7 @@ QgsVirtualLayerSourceSelect::QgsVirtualLayerSourceSelect( QWidget* parent, Qt::W
}

// 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 )
{
@@ -68,7 +68,7 @@ void TestProjectionIssues::initTestCase()

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

0 comments on commit c50033b

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