Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fix inefficient QString splitting
QString::split with single characters is about 10x faster than
QString::split using QStrings
  • Loading branch information
nyalldawson committed Nov 26, 2017
1 parent 144e9a2 commit 148380a
Show file tree
Hide file tree
Showing 22 changed files with 39 additions and 39 deletions.
4 changes: 2 additions & 2 deletions src/app/qgsoptions.cpp
Expand Up @@ -2346,11 +2346,11 @@ void QgsOptions::addScaleToScaleList( QListWidgetItem *newItem )
QListWidgetItem *duplicateItem = mListGlobalScales->findItems( newItem->text(), Qt::MatchExactly ).value( 0 );
delete duplicateItem;

int newDenominator = newItem->text().split( QStringLiteral( ":" ) ).value( 1 ).toInt();
int newDenominator = newItem->text().split( ':' ).value( 1 ).toInt();
int i;
for ( i = 0; i < mListGlobalScales->count(); i++ )
{
int denominator = mListGlobalScales->item( i )->text().split( QStringLiteral( ":" ) ).value( 1 ).toInt();
int denominator = mListGlobalScales->item( i )->text().split( ':' ).value( 1 ).toInt();
if ( newDenominator > denominator )
break;
}
Expand Down
4 changes: 2 additions & 2 deletions src/app/qgsprojectproperties.cpp
Expand Up @@ -1992,11 +1992,11 @@ void QgsProjectProperties::addScaleToScaleList( QListWidgetItem *newItem )
QListWidgetItem *duplicateItem = lstScales->findItems( newItem->text(), Qt::MatchExactly ).value( 0 );
delete duplicateItem;

int newDenominator = newItem->text().split( QStringLiteral( ":" ) ).value( 1 ).toInt();
int newDenominator = newItem->text().split( ':' ).value( 1 ).toInt();
int i;
for ( i = 0; i < lstScales->count(); i++ )
{
int denominator = lstScales->item( i )->text().split( QStringLiteral( ":" ) ).value( 1 ).toInt();
int denominator = lstScales->item( i )->text().split( ':' ).value( 1 ).toInt();
if ( newDenominator > denominator )
break;
}
Expand Down
6 changes: 3 additions & 3 deletions src/app/qgsversionmigration.cpp
Expand Up @@ -201,7 +201,7 @@ QgsError Qgs2To3Migration::migrateSettings()
if ( line.isEmpty() )
continue;

QStringList parts = line.split( ";" );
const QStringList parts = line.split( ';' );

Q_ASSERT_X( parts.count() == 2, "QgsVersionMigration::migrateSettings()", "Can't split line in 2 parts." );

Expand Down Expand Up @@ -327,10 +327,10 @@ QPair<QString, QString> Qgs2To3Migration::transformKey( QString fullOldKey, QStr

if ( newKeyPart.endsWith( "/*" ) )
{
QStringList newKeyparts = newKeyPart.split( "/" );
QStringList newKeyparts = newKeyPart.split( '/' );
// Throw away the *
newKeyparts.removeLast();
QStringList oldKeyParts = fullOldKey.split( "/" );
QStringList oldKeyParts = fullOldKey.split( '/' );
for ( int i = 0; i < newKeyparts.count(); ++i )
{
oldKeyParts.replace( i, newKeyparts.at( i ) );
Expand Down
2 changes: 1 addition & 1 deletion src/gui/qgsmetadatawidget.cpp
Expand Up @@ -715,7 +715,7 @@ void QgsMetadataWidget::updatePanel() const
if ( !categories.isEmpty() )
{
int row = categories.at( 0 )->row();
mCategoriesModel->setStringList( tabKeywords->item( row, 1 )->text().split( QStringLiteral( "," ) ) );
mCategoriesModel->setStringList( tabKeywords->item( row, 1 )->text().split( ',' ) );
}
else
{
Expand Down
6 changes: 3 additions & 3 deletions src/plugins/grass/qgsgrassmapcalc.cpp
Expand Up @@ -512,7 +512,7 @@ QStringList QgsGrassMapcalc::checkRegion()

struct Cell_head window;

QStringList mm = obj->value().split( QStringLiteral( "@" ) );
QStringList mm = obj->value().split( '@' );
if ( mm.size() < 1 )
continue;

Expand Down Expand Up @@ -571,7 +571,7 @@ bool QgsGrassMapcalc::inputRegion( struct Cell_head *window, QgsCoordinateRefere

struct Cell_head mapWindow;

QStringList mm = obj->value().split( QStringLiteral( "@" ) );
QStringList mm = obj->value().split( '@' );
if ( mm.size() < 1 )
continue;

Expand Down Expand Up @@ -652,7 +652,7 @@ void QgsGrassMapcalc::setOption()
{
case QgsGrassMapcalcObject::Map :
{
QStringList mapMapset = mObject->value().split( QStringLiteral( "@" ) );
QStringList mapMapset = mObject->value().split( '@' );
if ( !mMapComboBox->setCurrent( mapMapset.value( 0 ), mapMapset.value( 1 ) ) )
{
mMapComboBox->setEditText( mObject->value() );
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/grass/qgsgrassmodule.cpp
Expand Up @@ -672,7 +672,7 @@ void QgsGrassModule::run()
}
else // option
{
QStringList opt = arg.split( "=" );
QStringList opt = arg.split( '=' );
//env = "GIS_OPT_" + opt.takeFirst().toUpper();
//env += "=" + opt.join( "=" ); // rejoin rest
environment.insert( "GIS_OPT_" + opt.takeFirst().toUpper(), opt.join( "=" ) );
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/grass/qgsgrassmoduleinput.cpp
Expand Up @@ -858,7 +858,7 @@ QgsGrassModuleInput::QgsGrassModuleInput( QgsGrassModule *module,
{
int mask = 0;

Q_FOREACH ( const QString &typeName, opt.split( "," ) )
Q_FOREACH ( const QString &typeName, opt.split( ',' ) )
{
mask |= QgsGrass::vectorType( typeName );
}
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/grass/qgsgrassmoduleoptions.cpp
Expand Up @@ -845,7 +845,7 @@ bool QgsGrassModuleStandardOptions::getCurrentMapRegion( QgsGrassModuleInput *in
return false;
}

QStringList mm = input->currentMap().split( QStringLiteral( "@" ) );
QStringList mm = input->currentMap().split( '@' );
QString map = mm.value( 0 );
QString mapset = QgsGrass::getDefaultMapset();
if ( mm.size() > 1 )
Expand Down
10 changes: 5 additions & 5 deletions src/plugins/grass/qgsgrassmoduleparam.cpp
Expand Up @@ -436,7 +436,7 @@ QgsGrassModuleOption::QgsGrassModuleOption( QgsGrassModule *module, QString key,
{
QDomElement e = n.toElement();
QString val = e.text().trimmed();
minMax = val.split( QStringLiteral( "-" ) );
minMax = val.split( '-' );
if ( minMax.size() == 2 )
{
mHaveLimits = true;
Expand Down Expand Up @@ -902,7 +902,7 @@ void QgsGrassModuleGdalInput::updateQgisLayers()
}
else if ( vector->providerType() == QLatin1String( "ogr" ) )
{
QStringList items = provider->dataSourceUri().split( QStringLiteral( "|" ) );
QStringList items = provider->dataSourceUri().split( '|' );

if ( items.size() > 1 )
{
Expand All @@ -913,7 +913,7 @@ void QgsGrassModuleGdalInput::updateQgisLayers()

for ( int i = 1; i < items.size(); i++ )
{
QStringList args = items[i].split( QStringLiteral( "=" ) );
QStringList args = items[i].split( '=' );

if ( args.size() != 2 )
continue;
Expand Down Expand Up @@ -1219,7 +1219,7 @@ void QgsGrassModuleSelection::onLayerChanged()
{
QString uri = vectorLayer->dataProvider()->dataSourceUri();
QgsDebugMsg( "uri = " + uri );
QString layerCode = uri.split( QStringLiteral( "/" ) ).last();
QString layerCode = uri.split( '/' ).last();
if ( mLayerInput->currentLayerCodes().contains( layerCode ) )
{
// Qt::UserRole+1 may be also uri (AddLayer) but hardly matching layer id
Expand Down Expand Up @@ -1464,7 +1464,7 @@ void QgsGrassModuleFile::browse()

if ( mType == Multiple )
{
QString path = mLineEdit->text().split( QStringLiteral( "," ) ).first();
QString path = mLineEdit->text().split( ',' ).first();
if ( path.isEmpty() )
path = lastDir;
else
Expand Down
2 changes: 1 addition & 1 deletion src/providers/arcgisrest/qgsafsprovider.cpp
Expand Up @@ -59,7 +59,7 @@ QgsAfsProvider::QgsAfsProvider( const QString &uri )
mLayerDescription = layerData[QStringLiteral( "description" )].toString();

// Set extent
QStringList coords = mSharedData->mDataSource.param( QStringLiteral( "bbox" ) ).split( QStringLiteral( "," ) );
QStringList coords = mSharedData->mDataSource.param( QStringLiteral( "bbox" ) ).split( ',' );
if ( coords.size() == 4 )
{
bool xminOk = false, yminOk = false, xmaxOk = false, ymaxOk = false;
Expand Down
2 changes: 1 addition & 1 deletion src/providers/arcgisrest/qgsamsdataitems.cpp
Expand Up @@ -103,7 +103,7 @@ QVector<QgsDataItem *> QgsAmsConnectionItem::createChildren()
QString format = QStringLiteral( "jpg" );
bool found = false;
QList<QByteArray> supportedFormats = QImageReader::supportedImageFormats();
foreach ( const QString &encoding, serviceData["supportedImageFormatTypes"].toString().split( "," ) )
foreach ( const QString &encoding, serviceData["supportedImageFormatTypes"].toString().split( ',' ) )
{
foreach ( const QByteArray &fmt, supportedFormats )
{
Expand Down
2 changes: 1 addition & 1 deletion src/providers/arcgisrest/qgsamssourceselect.cpp
Expand Up @@ -44,7 +44,7 @@ bool QgsAmsSourceSelect::connectToService( const QgsOwsConnection &connection )
return false;
}

populateImageEncodings( serviceInfoMap[QStringLiteral( "supportedImageFormatTypes" )].toString().split( QStringLiteral( "," ) ) );
populateImageEncodings( serviceInfoMap[QStringLiteral( "supportedImageFormatTypes" )].toString().split( ',' ) );

QStringList layerErrors;
foreach ( const QVariant &layerInfo, serviceInfoMap["layers"].toList() )
Expand Down
2 changes: 1 addition & 1 deletion src/providers/arcgisrest/qgsarcgisrestutils.cpp
Expand Up @@ -388,7 +388,7 @@ QVariantMap QgsArcGisRestUtils::getObjects( const QString &layerurl, const QList
QUrl queryUrl( layerurl + "/query" );
queryUrl.addQueryItem( QStringLiteral( "f" ), QStringLiteral( "json" ) );
queryUrl.addQueryItem( QStringLiteral( "objectIds" ), ids.join( QStringLiteral( "," ) ) );
QString wkid = crs.indexOf( QLatin1String( ":" ) ) >= 0 ? crs.split( QStringLiteral( ":" ) )[1] : QLatin1String( "" );
QString wkid = crs.indexOf( QLatin1String( ":" ) ) >= 0 ? crs.split( ':' )[1] : QLatin1String( "" );
queryUrl.addQueryItem( QStringLiteral( "inSR" ), wkid );
queryUrl.addQueryItem( QStringLiteral( "outSR" ), wkid );
QString outFields = fetchAttributes.join( QStringLiteral( "," ) );
Expand Down
8 changes: 4 additions & 4 deletions src/providers/grass/qgsgrass.cpp
Expand Up @@ -1515,7 +1515,7 @@ QStringList QgsGrass::grassObjects( const QgsGrassObject &mapsetObject, QgsGrass
fullName = fullName.trimmed();
if ( !fullName.isEmpty() )
{
QStringList nameMapset = fullName.split( QStringLiteral( "@" ) );
QStringList nameMapset = fullName.split( '@' );
if ( nameMapset.value( 1 ) == mapsetObject.mapset() || nameMapset.value( 1 ).isEmpty() )
{
list << nameMapset.value( 0 );
Expand Down Expand Up @@ -2133,7 +2133,7 @@ QgsRectangle QgsGrass::extent( const QString &gisdbase, const QString &location,
try
{
QString str = getInfo( QStringLiteral( "window" ), gisdbase, location, mapset, map, type );
QStringList list = str.split( QStringLiteral( "," ) );
QStringList list = str.split( ',' );
if ( list.size() != 4 )
{
throw QgsGrass::Exception( "Cannot parse GRASS map extent: " + str );
Expand All @@ -2157,7 +2157,7 @@ void QgsGrass::size( const QString &gisdbase, const QString &location, const QSt
try
{
QString str = getInfo( QStringLiteral( "size" ), gisdbase, location, mapset, map, QgsGrassObject::Raster );
QStringList list = str.split( QStringLiteral( "," ) );
QStringList list = str.split( ',' );
if ( list.size() != 2 )
{
throw QgsGrass::Exception( "Cannot parse GRASS map size: " + str );
Expand Down Expand Up @@ -2250,7 +2250,7 @@ QMap<QString, QString> QgsGrass::query( const QString &gisdbase, const QString &
try
{
QString str = getInfo( QStringLiteral( "query" ), gisdbase, location, mapset, map, type, x, y );
QStringList list = str.trimmed().split( QStringLiteral( ":" ) );
QStringList list = str.trimmed().split( ':' );
if ( list.size() == 2 )
{
result[list[0]] = list[1];
Expand Down
4 changes: 2 additions & 2 deletions src/providers/grass/qgsgrassprovidermodule.cpp
Expand Up @@ -559,8 +559,8 @@ QVector<QgsDataItem *> QgsGrassMapsetItem::createChildren()
// somewhere not properly escaped (there was bug in QgsMimeDataUtils for example)
QString uri = mDirPath + "/" + name + "/" + layerName;
QgsLayerItem::LayerType layerType = QgsLayerItem::Vector;
QString typeName = layerName.split( QStringLiteral( "_" ) ).value( 1 );
QString baseLayerName = layerName.split( QStringLiteral( "_" ) ).value( 0 );
QString typeName = layerName.split( '_' ).value( 1 );
QString baseLayerName = layerName.split( '_' ).value( 0 );

if ( typeName == QLatin1String( "point" ) || typeName == QLatin1String( "node" ) )
layerType = QgsLayerItem::Point;
Expand Down
2 changes: 1 addition & 1 deletion src/providers/grass/qgsgrassrasterprovider.cpp
Expand Up @@ -675,7 +675,7 @@ double QgsGrassRasterValue::value( double x, double y, bool *ok )

// TODO: use doubles instead of strings

QStringList list = str.trimmed().split( QStringLiteral( ":" ) );
QStringList list = str.trimmed().split( ':' );
if ( list.size() == 2 )
{
if ( list[1] == QLatin1String( "error" ) ) return value;
Expand Down
2 changes: 1 addition & 1 deletion src/providers/wfs/qgswfsprovider.cpp
Expand Up @@ -285,7 +285,7 @@ bool QgsWFSProvider::processSQL( const QString &sqlString, QString &errorMsg, QS
if ( sql.hasParserError() )
{
QString parserErrorString( sql.parserErrorString() );
QStringList parts( parserErrorString.split( QStringLiteral( "," ) ) );
QStringList parts( parserErrorString.split( ',' ) );
parserErrorString.clear();
Q_FOREACH ( const QString &part, parts )
{
Expand Down
2 changes: 1 addition & 1 deletion src/server/services/wfs/qgswfsparameters.cpp
Expand Up @@ -383,7 +383,7 @@ namespace QgsWfs

if ( !bbox.isEmpty() )
{
QStringList corners = bbox.split( "," );
const QStringList corners = bbox.split( ',' );

if ( corners.size() == 4 )
{
Expand Down
2 changes: 1 addition & 1 deletion src/server/services/wfs/qgswfstransaction.cpp
Expand Up @@ -933,7 +933,7 @@ namespace QgsWfs
}

// get bbox corners
QStringList corners = bbox.split( "," );
const QStringList corners = bbox.split( ',' );
if ( corners.size() != 4 )
{
throw QgsRequestNotWellFormedException( QStringLiteral( "BBOX has to be composed of 4 elements: '%1'" ).arg( bbox ) );
Expand Down
2 changes: 1 addition & 1 deletion src/server/services/wfs/qgswfstransaction_1_0_0.cpp
Expand Up @@ -916,7 +916,7 @@ namespace QgsWfs
}

// get bbox corners
QStringList corners = bbox.split( "," );
const QStringList corners = bbox.split( ',' );
if ( corners.size() != 4 )
{
throw QgsRequestNotWellFormedException( QStringLiteral( "BBOX has to be composed of 4 elements: '%1'" ).arg( bbox ) );
Expand Down
8 changes: 4 additions & 4 deletions src/server/services/wms/qgswmsparameters.cpp
Expand Up @@ -882,7 +882,7 @@ namespace QgsWms

if ( !bbox.isEmpty() )
{
QStringList corners = bbox.split( "," );
QStringList corners = bbox.split( ',' );

if ( corners.size() == 4 )
{
Expand Down Expand Up @@ -1670,7 +1670,7 @@ namespace QgsWms
QMultiMap<QString, QString> layerFilters;
Q_FOREACH ( QString f, filter )
{
QStringList splits = f.split( ":" );
const QStringList splits = f.split( ':' );
if ( splits.size() == 2 )
{
layerFilters.insert( splits[0], splits[1] );
Expand All @@ -1687,7 +1687,7 @@ namespace QgsWms
QMultiMap<QString, QString> layerSelections;
Q_FOREACH ( QString s, selection )
{
QStringList splits = s.split( ":" );
const QStringList splits = s.split( ':' );
if ( splits.size() == 2 )
{
layerSelections.insert( splits[0], splits[1] );
Expand Down Expand Up @@ -1728,7 +1728,7 @@ namespace QgsWms
it = layerSelections.find( layer );
while ( it != layerSelections.end() && it.key() == layer )
{
param.mSelection << it.value().split( "," );
param.mSelection << it.value().split( ',' );
++it;
}
}
Expand Down
2 changes: 1 addition & 1 deletion tests/src/core/testqgsmaprendererjob.cpp
Expand Up @@ -294,7 +294,7 @@ void TestQgsMapRendererJob::testFourAdjacentTiles()
QgsMapSettings mapSettings;

//extent
QStringList rectCoords = bboxList.at( i ).split( QStringLiteral( "," ) );
QStringList rectCoords = bboxList.at( i ).split( ',' );
if ( rectCoords.size() != 4 )
{
QFAIL( "bbox string invalid" );
Expand Down

0 comments on commit 148380a

Please sign in to comment.