Skip to content

Commit b7e1cae

Browse files
committed
Switch double quoted single character to single quotes for some
QString methods Using single quotes is a significant performance boost. Rough benchmarks indicate the QString single quote methods take about 15% of the time the double quote variants take.
1 parent c522bb1 commit b7e1cae

File tree

270 files changed

+1199
-1199
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

270 files changed

+1199
-1199
lines changed

src/analysis/interpolation/qgsgridfilewriter.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ int QgsGridFileWriter::writeFile( bool showProgressDialog )
8686
{
8787
if ( mInterpolator->interpolatePoint( currentXValue, currentYValue, interpolatedValue ) == 0 )
8888
{
89-
outStream << interpolatedValue << " ";
89+
outStream << interpolatedValue << ' ';
9090
}
9191
else
9292
{
@@ -114,7 +114,7 @@ int QgsGridFileWriter::writeFile( bool showProgressDialog )
114114
QgsVectorLayer* vl = ld.vectorLayer;
115115
QString crs = vl->crs().toWkt();
116116
QFileInfo fi( mOutputFilePath );
117-
QString fileName = fi.absolutePath() + "/" + fi.completeBaseName() + ".prj";
117+
QString fileName = fi.absolutePath() + '/' + fi.completeBaseName() + ".prj";
118118
QFile prjFile( fileName );
119119
if ( !prjFile.open( QFile::WriteOnly ) )
120120
{

src/analysis/openstreetmap/qgsosmdatabase.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,7 @@ bool QgsOSMDatabase::createSpatialTable( const QString& tableName, const QString
336336
QString sqlCreateTable = QString( "CREATE TABLE %1 (id INTEGER PRIMARY KEY" ).arg( quotedIdentifier( tableName ) );
337337
for ( int i = 0; i < tagKeys.count(); ++i )
338338
sqlCreateTable += QString( ", %1 TEXT" ).arg( quotedIdentifier( tagKeys[i] ) );
339-
sqlCreateTable += ")";
339+
sqlCreateTable += ')';
340340

341341
char *errMsg = NULL;
342342
int ret = sqlite3_exec( mDatabase, sqlCreateTable.toUtf8().constData(), NULL, NULL, &errMsg );
@@ -530,7 +530,7 @@ void QgsOSMDatabase::exportSpatiaLiteWays( bool closed, const QString& tableName
530530

531531
QString QgsOSMDatabase::quotedIdentifier( QString id )
532532
{
533-
id.replace( "\"", "\"\"" );
533+
id.replace( '\"', "\"\"" );
534534
return QString( "\"%1\"" ).arg( id );
535535
}
536536

@@ -539,7 +539,7 @@ QString QgsOSMDatabase::quotedValue( QString value )
539539
if ( value.isNull() )
540540
return "NULL";
541541

542-
value.replace( "'", "''" );
542+
value.replace( '\'', "''" );
543543
return QString( "'%1'" ).arg( value );
544544
}
545545

src/analysis/openstreetmap/qgsosmimport.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,10 +141,10 @@ bool QgsOSMXmlImport::createDatabase()
141141
if ( ret == SQLITE_OK && rows == 1 && columns == 1 )
142142
{
143143
QString version = QString::fromUtf8( results[1] );
144-
QStringList parts = version.split( " ", QString::SkipEmptyParts );
144+
QStringList parts = version.split( ' ', QString::SkipEmptyParts );
145145
if ( parts.size() >= 1 )
146146
{
147-
QStringList verparts = parts[0].split( ".", QString::SkipEmptyParts );
147+
QStringList verparts = parts[0].split( '.', QString::SkipEmptyParts );
148148
above41 = verparts.size() >= 2 && ( verparts[0].toInt() > 4 || ( verparts[0].toInt() == 4 && verparts[1].toInt() >= 1 ) );
149149
}
150150
}

src/analysis/raster/qgsrelief.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -560,7 +560,7 @@ bool QgsRelief::exportFrequencyDistributionToCsv( const QString& file )
560560
QTextStream outstream( &outFile );
561561
for ( int i = 0; i < 252; ++i )
562562
{
563-
outstream << QString::number( i ) + "," + QString::number( frequency[i] ) << endl;
563+
outstream << QString::number( i ) + ',' + QString::number( frequency[i] ) << endl;
564564
}
565565
outFile.close();
566566
return true;

src/analysis/vector/qgstransectsample.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ int QgsTransectSample::createSample( QProgressDialog* pd )
210210
samplePointFeature.setAttribute( "id", nTotalTransects + 1 );
211211
samplePointFeature.setAttribute( "station_id", nCreatedTransects + 1 );
212212
samplePointFeature.setAttribute( "stratum_id", strataId );
213-
samplePointFeature.setAttribute( "station_code", strataId.toString() + "_" + QString::number( nCreatedTransects + 1 ) );
213+
samplePointFeature.setAttribute( "station_code", strataId.toString() + '_' + QString::number( nCreatedTransects + 1 ) );
214214
samplePointFeature.setAttribute( "start_lat", latLongSamplePoint.y() );
215215
samplePointFeature.setAttribute( "start_long", latLongSamplePoint.x() );
216216

@@ -279,7 +279,7 @@ int QgsTransectSample::createSample( QProgressDialog* pd )
279279
sampleLineFeature.setAttribute( "id", nTotalTransects + 1 );
280280
sampleLineFeature.setAttribute( "station_id", nCreatedTransects + 1 );
281281
sampleLineFeature.setAttribute( "stratum_id", strataId );
282-
sampleLineFeature.setAttribute( "station_code", strataId.toString() + "_" + QString::number( nCreatedTransects + 1 ) );
282+
sampleLineFeature.setAttribute( "station_code", strataId.toString() + '_' + QString::number( nCreatedTransects + 1 ) );
283283
sampleLineFeature.setAttribute( "start_lat", latLongSamplePoint.y() );
284284
sampleLineFeature.setAttribute( "start_long", latLongSamplePoint.x() );
285285
sampleLineFeature.setAttribute( "bearing", bearing );

src/app/composer/qgscomposer.cpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2088,7 +2088,7 @@ void QgsComposer::exportCompositionAsImage( QgsComposer::OutputMode mode )
20882088
else
20892089
{
20902090
QFileInfo fi( fileNExt.first );
2091-
outputFilePath = fi.absolutePath() + "/" + fi.baseName() + "_" + QString::number( i + 1 ) + "." + fi.suffix();
2091+
outputFilePath = fi.absolutePath() + '/' + fi.baseName() + '_' + QString::number( i + 1 ) + '.' + fi.suffix();
20922092
}
20932093

20942094
saveOk = image.save( outputFilePath, fileNExt.second.toLocal8Bit().constData() );
@@ -2115,8 +2115,8 @@ void QgsComposer::exportCompositionAsImage( QgsComposer::OutputMode mode )
21152115
QFileInfo fi( outputFilePath );
21162116
// build the world file name
21172117
QString outputSuffix = fi.suffix();
2118-
QString worldFileName = fi.absolutePath() + "/" + fi.baseName() + "."
2119-
+ outputSuffix.at( 0 ) + outputSuffix.at( fi.suffix().size() - 1 ) + "w";
2118+
QString worldFileName = fi.absolutePath() + '/' + fi.baseName() + '.'
2119+
+ outputSuffix.at( 0 ) + outputSuffix.at( fi.suffix().size() - 1 ) + 'w';
21202120

21212121
writeWorldFile( worldFileName, a, b, c, d, e, f );
21222122
}
@@ -2185,7 +2185,7 @@ void QgsComposer::exportCompositionAsImage( QgsComposer::OutputMode mode )
21852185
}
21862186
QString dir = s.at( 0 );
21872187
QString format = box->currentText();
2188-
QString fileExt = "." + format;
2188+
QString fileExt = '.' + format;
21892189

21902190
if ( dir.isEmpty() )
21912191
{
@@ -2309,7 +2309,7 @@ void QgsComposer::exportCompositionAsImage( QgsComposer::OutputMode mode )
23092309
{
23102310
//append page number
23112311
QFileInfo fi( filename );
2312-
imageFilename = fi.absolutePath() + "/" + fi.baseName() + "_" + QString::number( i + 1 ) + "." + fi.suffix();
2312+
imageFilename = fi.absolutePath() + '/' + fi.baseName() + '_' + QString::number( i + 1 ) + '.' + fi.suffix();
23132313
}
23142314

23152315
bool saveOk = image.save( imageFilename, format.toLocal8Bit().constData() );
@@ -2336,8 +2336,8 @@ void QgsComposer::exportCompositionAsImage( QgsComposer::OutputMode mode )
23362336
QFileInfo fi( imageFilename );
23372337
// build the world file name
23382338
QString outputSuffix = fi.suffix();
2339-
QString worldFileName = fi.absolutePath() + "/" + fi.baseName() + "."
2340-
+ outputSuffix.at( 0 ) + outputSuffix.at( fi.suffix().size() - 1 ) + "w";
2339+
QString worldFileName = fi.absolutePath() + '/' + fi.baseName() + '.'
2340+
+ outputSuffix.at( 0 ) + outputSuffix.at( fi.suffix().size() - 1 ) + 'w';
23412341

23422342
writeWorldFile( worldFileName, a, b, c, d, e, f );
23432343
}
@@ -2621,7 +2621,7 @@ void QgsComposer::exportCompositionAsSVG( QgsComposer::OutputMode mode )
26212621
else
26222622
{
26232623
QFileInfo fi( outputFileName );
2624-
currentFileName = fi.absolutePath() + "/" + fi.baseName() + "_" + QString::number( i + 1 ) + "." + fi.suffix();
2624+
currentFileName = fi.absolutePath() + '/' + fi.baseName() + '_' + QString::number( i + 1 ) + '.' + fi.suffix();
26252625
generator.setFileName( currentFileName );
26262626
}
26272627

@@ -2787,7 +2787,7 @@ void QgsComposer::exportCompositionAsSVG( QgsComposer::OutputMode mode )
27872787
QString errorMsg;
27882788
int errorLine;
27892789
if ( ! doc.setContent( &svgBuffer, false, &errorMsg, &errorLine ) )
2790-
QMessageBox::warning( 0, tr( "SVG error" ), tr( "There was an error in SVG output for SVG layer " ) + layerName + tr( " on page " ) + QString::number( i + 1 ) + "(" + errorMsg + ")" );
2790+
QMessageBox::warning( 0, tr( "SVG error" ), tr( "There was an error in SVG output for SVG layer " ) + layerName + tr( " on page " ) + QString::number( i + 1 ) + '(' + errorMsg + ')' );
27912791
if ( 1 == svgLayerId )
27922792
{
27932793
svg = QDomDocument( doc.doctype() );
@@ -2813,7 +2813,7 @@ void QgsComposer::exportCompositionAsSVG( QgsComposer::OutputMode mode )
28132813
}
28142814
}
28152815
QFileInfo fi( outputFileName );
2816-
QString currentFileName = i == 0 ? outputFileName : fi.absolutePath() + "/" + fi.baseName() + "_" + QString::number( i + 1 ) + "." + fi.suffix();
2816+
QString currentFileName = i == 0 ? outputFileName : fi.absolutePath() + '/' + fi.baseName() + '_' + QString::number( i + 1 ) + '.' + fi.suffix();
28172817
QFile out( currentFileName );
28182818
bool openOk = out.open( QIODevice::WriteOnly | QIODevice::Text );
28192819
if ( !openOk )
@@ -4159,7 +4159,7 @@ void QgsComposer::loadAtlasPredefinedScalesFromProject()
41594159
// default to global map tool scales
41604160
QSettings settings;
41614161
QString scalesStr( settings.value( "Map/scales", PROJECT_SCALES ).toString() );
4162-
scales = scalesStr.split( "," );
4162+
scales = scalesStr.split( ',' );
41634163
}
41644164

41654165
for ( QStringList::const_iterator scaleIt = scales.constBegin(); scaleIt != scales.constEnd(); ++scaleIt )

src/app/composer/qgscomposermapwidget.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1171,7 +1171,7 @@ bool QgsComposerMapWidget::hasPredefinedScales() const
11711171
// default to global map tool scales
11721172
QSettings settings;
11731173
QString scalesStr( settings.value( "Map/scales", PROJECT_SCALES ).toString() );
1174-
QStringList myScalesList = scalesStr.split( "," );
1174+
QStringList myScalesList = scalesStr.split( ',' );
11751175
return myScalesList.size() > 0 && myScalesList[0] != "";
11761176
}
11771177
return true;
@@ -2534,7 +2534,7 @@ void QgsComposerMapWidget::on_mOverviewFrameMapComboBox_currentIndexChanged( con
25342534

25352535
//extract id
25362536
bool conversionOk;
2537-
QStringList textSplit = text.split( " " );
2537+
QStringList textSplit = text.split( ' ' );
25382538
if ( textSplit.size() < 1 )
25392539
{
25402540
return;

src/app/composer/qgscomposerpicturewidget.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ void QgsComposerPictureWidget::on_mComposerMapComboBox_activated( const QString
300300
//extract id
301301
int id;
302302
bool conversionOk;
303-
QStringList textSplit = text.split( " " );
303+
QStringList textSplit = text.split( ' ' );
304304
if ( textSplit.size() < 1 )
305305
{
306306
return;

src/app/composer/qgscomposerscalebarwidget.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ void QgsComposerScaleBarWidget::on_mMapComboBox_activated( const QString& text )
149149
//extract id
150150
int id;
151151
bool conversionOk;
152-
QStringList textSplit = text.split( " " );
152+
QStringList textSplit = text.split( ' ' );
153153
if ( textSplit.size() < 1 )
154154
{
155155
return;

src/app/main.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -606,7 +606,7 @@ int main( int argc, char *argv[] )
606606
{
607607
QgsLocaleNumC l;
608608
QString ext( args[++i] );
609-
QStringList coords( ext.split( "," ) );
609+
QStringList coords( ext.split( ',' ) );
610610

611611
if ( coords.size() != 4 )
612612
{
@@ -1115,7 +1115,7 @@ int main( int argc, char *argv[] )
11151115
{
11161116
#ifdef Q_OS_WIN
11171117
//replace backslashes with forward slashes
1118-
pythonfile.replace( "\\", "/" );
1118+
pythonfile.replace( '\\', '/' );
11191119
#endif
11201120
QgsPythonRunner::run( QString( "execfile('%1')" ).arg( pythonfile ) );
11211121
}

src/app/nodetool/qgsselectedfeature.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ void QgsSelectedFeature::addError( QgsGeometry::Error e )
201201
{
202202
mGeomErrors << e;
203203
if ( !mTip.isEmpty() )
204-
mTip += "\n";
204+
mTip += '\n';
205205
mTip += e.what();
206206

207207
if ( e.hasWhere() )

src/app/ogr/qgsnewogrconnection.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,19 +41,19 @@ QgsNewOgrConnection::QgsNewOgrConnection( QWidget *parent, const QString& connTy
4141
restoreGeometry( settings.value( "/Windows/OGRDatabaseConnection/geometry" ).toByteArray() );
4242

4343
//add database drivers
44-
QStringList dbDrivers = QgsProviderRegistry::instance()->databaseDrivers().split( ";" );
44+
QStringList dbDrivers = QgsProviderRegistry::instance()->databaseDrivers().split( ';' );
4545
for ( int i = 0; i < dbDrivers.count(); i++ )
4646
{
4747
QString dbDrive = dbDrivers.at( i );
48-
cmbDatabaseTypes->addItem( dbDrive.split( "," ).at( 0 ) );
48+
cmbDatabaseTypes->addItem( dbDrive.split( ',' ).at( 0 ) );
4949
}
5050
txtName->setEnabled( true );
5151
cmbDatabaseTypes->setEnabled( true );
5252
if ( !connName.isEmpty() )
5353
{
5454
// populate the dialog with the information stored for the connection
5555
// populate the fields with the stored setting parameters
56-
QString key = "/" + connType + "/connections/" + connName;
56+
QString key = '/' + connType + "/connections/" + connName;
5757
txtHost->setText( settings.value( key + "/host" ).toString() );
5858
txtDatabase->setText( settings.value( key + "/database" ).toString() );
5959
QString port = settings.value( key + "/port" ).toString();
@@ -104,7 +104,7 @@ void QgsNewOgrConnection::testConnection()
104104
void QgsNewOgrConnection::accept()
105105
{
106106
QSettings settings;
107-
QString baseKey = "/" + cmbDatabaseTypes->currentText() + "/connections/";
107+
QString baseKey = '/' + cmbDatabaseTypes->currentText() + "/connections/";
108108
settings.setValue( baseKey + "selected", txtName->text() );
109109

110110
// warn if entry was renamed to an existing connection

src/app/ogr/qgsogrhelperfunctions.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ QString createDatabaseURI( const QString& connectionType, const QString& host, c
3434
if ( port.isEmpty() )
3535
port = "5151";
3636

37-
uri = "SDE:" + host + ",PORT:" + port + "," + database + "," + user + "," + password;
37+
uri = "SDE:" + host + ",PORT:" + port + ',' + database + ',' + user + ',' + password;
3838
}
3939
else if ( connectionType == "Informix DataBlade" )
4040
{
@@ -116,26 +116,26 @@ QString createDatabaseURI( const QString& connectionType, const QString& host, c
116116
if (( !user.isEmpty() && !password.isEmpty() ) ||
117117
( user.isEmpty() && password.isEmpty() ) )
118118
{
119-
uri += "/";
119+
uri += '/';
120120
if ( !password.isEmpty() )
121121
uri += password;
122122
}
123123

124124
if ( !host.isEmpty() || !database.isEmpty() )
125125
{
126-
uri += "@";
126+
uri += '@';
127127

128128
if ( !host.isEmpty() )
129129
{
130130
uri += host;
131131
if ( !port.isEmpty() )
132-
uri += ":" + port;
132+
uri += ':' + port;
133133
}
134134

135135
if ( !database.isEmpty() )
136136
{
137137
if ( !host.isEmpty() )
138-
uri += "/";
138+
uri += '/';
139139
uri += database;
140140
}
141141
}
@@ -146,11 +146,11 @@ QString createDatabaseURI( const QString& connectionType, const QString& host, c
146146
{
147147
if ( password.isEmpty() )
148148
{
149-
uri = "ODBC:" + user + "@" + database;
149+
uri = "ODBC:" + user + '@' + database;
150150
}
151151
else
152152
{
153-
uri = "ODBC:" + user + "/" + password + "@" + database;
153+
uri = "ODBC:" + user + '/' + password + '@' + database;
154154
}
155155

156156
}
@@ -164,7 +164,7 @@ QString createDatabaseURI( const QString& connectionType, const QString& host, c
164164
}
165165
else if ( connectionType == "PostgreSQL" )
166166
{
167-
uri = "PG:dbname='" + database + "'";
167+
uri = "PG:dbname='" + database + '\'';
168168

169169
if ( !host.isEmpty() )
170170
{
@@ -182,7 +182,7 @@ QString createDatabaseURI( const QString& connectionType, const QString& host, c
182182
uri += QString( " password='%1'" ).arg( password );
183183
}
184184

185-
uri += " ";
185+
uri += ' ';
186186
}
187187

188188
QgsDebugMsg( "Connection type is=" + connectionType + " and uri=" + uri );

0 commit comments

Comments
 (0)