Skip to content
Permalink
Browse files

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 148380abef1548978b4787e201b35a3691d1467c
@@ -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;
}
@@ -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;
}
@@ -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." );

@@ -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 ) );
@@ -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
{
@@ -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;

@@ -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;

@@ -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() );
@@ -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( "=" ) );
@@ -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 );
}
@@ -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 )
@@ -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;
@@ -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 )
{
@@ -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;
@@ -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
@@ -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
@@ -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;
@@ -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 )
{
@@ -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() )
@@ -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( "," ) );
@@ -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 );
@@ -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 );
@@ -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 );
@@ -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];
@@ -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;
@@ -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;
@@ -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 )
{
@@ -383,7 +383,7 @@ namespace QgsWfs

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

if ( corners.size() == 4 )
{
@@ -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 ) );
@@ -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 ) );
@@ -882,7 +882,7 @@ namespace QgsWms

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

if ( corners.size() == 4 )
{
@@ -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] );
@@ -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] );
@@ -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;
}
}
@@ -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" );

0 comments on commit 148380a

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