Skip to content

Commit ef51107

Browse files
committedOct 22, 2016
Fix clazy "qstring-ref" warnings
From the clazy docs: Finds places where QString::fooRef() should be used instead of QString::foo(), to avoid temporary heap allocations eg str.mid(5).toInt(ok) // BAD str.midRef(5).toInt(ok) // GOOD
1 parent a51bebd commit ef51107

File tree

10 files changed

+19
-19
lines changed

10 files changed

+19
-19
lines changed
 

‎src/app/main.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1126,7 +1126,7 @@ int main( int argc, char *argv[] )
11261126
break;
11271127
}
11281128

1129-
coords[i] = QString( myInitialExtent.mid( posOld, pos - posOld ) ).toDouble( &ok );
1129+
coords[i] = myInitialExtent.midRef( posOld, pos - posOld ).toDouble( &ok );
11301130
if ( !ok )
11311131
break;
11321132

@@ -1135,7 +1135,7 @@ int main( int argc, char *argv[] )
11351135

11361136
// parse last coordinate
11371137
if ( ok )
1138-
coords[3] = QString( myInitialExtent.mid( posOld ) ).toDouble( &ok );
1138+
coords[3] = myInitialExtent.midRef( posOld ).toDouble( &ok );
11391139

11401140
if ( !ok )
11411141
{

‎src/app/qgsprojectproperties.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1908,14 +1908,14 @@ void QgsProjectProperties::populateEllipsoidList()
19081908
// Crash if no column?
19091909
para1 = ( const char * )sqlite3_column_text( myPreparedStatement, 2 );
19101910
para2 = ( const char * )sqlite3_column_text( myPreparedStatement, 3 );
1911-
myItem.semiMajor = para1.mid( 2 ).toDouble();
1911+
myItem.semiMajor = para1.midRef( 2 ).toDouble();
19121912
if ( para2.left( 2 ) == "b=" )
19131913
{
1914-
myItem.semiMinor = para2.mid( 2 ).toDouble();
1914+
myItem.semiMinor = para2.midRef( 2 ).toDouble();
19151915
}
19161916
else if ( para2.left( 3 ) == "rf=" )
19171917
{
1918-
double invFlattening = para2.mid( 3 ).toDouble();
1918+
double invFlattening = para2.midRef( 3 ).toDouble();
19191919
if ( invFlattening != 0.0 )
19201920
{
19211921
myItem.semiMinor = myItem.semiMajor - ( myItem.semiMajor / invFlattening );

‎src/core/qgscolorramp.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ QgsColorRamp* QgsGradientColorRamp::create( const QgsStringMap& props )
7272
continue;
7373

7474
QColor c = QgsSymbolLayerUtils::decodeColor( stop.mid( i + 1 ) );
75-
stops.append( QgsGradientStop( stop.left( i ).toDouble(), c ) );
75+
stops.append( QgsGradientStop( stop.leftRef( i ).toDouble(), c ) );
7676
}
7777
}
7878

‎src/core/qgscoordinatereferencesystem.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -500,7 +500,7 @@ bool QgsCoordinateReferenceSystem::hasAxisInverted() const
500500
{
501501
OGRSpatialReferenceH crs = OSRNewSpatialReference( nullptr );
502502

503-
if ( OSRImportFromEPSGA( crs, d->mAuthId.mid( 5 ).toInt() ) == OGRERR_NONE )
503+
if ( OSRImportFromEPSGA( crs, d->mAuthId.midRef( 5 ).toInt() ) == OGRERR_NONE )
504504
{
505505
OSRGetAxis( crs, OSRIsGeographic( crs ) ? "GEOGCS" : "PROJCS", 0, &orientation );
506506
}
@@ -1750,7 +1750,7 @@ bool QgsCoordinateReferenceSystem::loadWkts( QHash<int, QString> &wkts, const ch
17501750
return false;
17511751

17521752
bool ok;
1753-
int epsg = line.left( pos ).toInt( &ok );
1753+
int epsg = line.leftRef( pos ).toInt( &ok );
17541754
if ( !ok )
17551755
return false;
17561756

@@ -1791,7 +1791,7 @@ bool QgsCoordinateReferenceSystem::loadIds( QHash<int, QString> &wkts )
17911791
continue;
17921792

17931793
bool ok;
1794-
int epsg = line.left( pos ).toInt( &ok );
1794+
int epsg = line.leftRef( pos ).toInt( &ok );
17951795
if ( !ok )
17961796
continue;
17971797

‎src/core/qgsdistancearea.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ bool QgsDistanceArea::setEllipsoid( const QString& ellipsoid )
191191

192192
// get major semiaxis
193193
if ( radius.left( 2 ) == "a=" )
194-
mSemiMajor = radius.mid( 2 ).toDouble();
194+
mSemiMajor = radius.midRef( 2 ).toDouble();
195195
else
196196
{
197197
QgsDebugMsg( QString( "setEllipsoid: wrong format of radius field: '%1'" ).arg( radius ) );
@@ -203,12 +203,12 @@ bool QgsDistanceArea::setEllipsoid( const QString& ellipsoid )
203203
// second one must be computed using formula: invf = a/(a-b)
204204
if ( parameter2.left( 2 ) == "b=" )
205205
{
206-
mSemiMinor = parameter2.mid( 2 ).toDouble();
206+
mSemiMinor = parameter2.midRef( 2 ).toDouble();
207207
mInvFlattening = mSemiMajor / ( mSemiMajor - mSemiMinor );
208208
}
209209
else if ( parameter2.left( 3 ) == "rf=" )
210210
{
211-
mInvFlattening = parameter2.mid( 3 ).toDouble();
211+
mInvFlattening = parameter2.midRef( 3 ).toDouble();
212212
mSemiMinor = mSemiMajor - ( mSemiMajor / mInvFlattening );
213213
}
214214
else

‎src/core/qgsogcutils.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2910,7 +2910,7 @@ QDomElement QgsOgcUtilsSQLStatementToFilter::toOgcFilter( const QgsSQLStatement:
29102910
static QString mapBinarySpatialToOgc( const QString& name )
29112911
{
29122912
QString nameCompare( name );
2913-
if ( name.size() > 3 && name.mid( 0, 3 ).compare( "ST_", Qt::CaseInsensitive ) == 0 )
2913+
if ( name.size() > 3 && name.midRef( 0, 3 ).compare( "ST_", Qt::CaseInsensitive ) == 0 )
29142914
nameCompare = name.mid( 3 );
29152915
QStringList spatialOps;
29162916
spatialOps << "BBOX" << "Intersects" << "Contains" << "Crosses" << "Equals"
@@ -2926,7 +2926,7 @@ static QString mapBinarySpatialToOgc( const QString& name )
29262926
static QString mapTernarySpatialToOgc( const QString& name )
29272927
{
29282928
QString nameCompare( name );
2929-
if ( name.size() > 3 && name.mid( 0, 3 ).compare( "ST_", Qt::CaseInsensitive ) == 0 )
2929+
if ( name.size() > 3 && name.midRef( 0, 3 ).compare( "ST_", Qt::CaseInsensitive ) == 0 )
29302930
nameCompare = name.mid( 3 );
29312931
if ( nameCompare.compare( "DWithin", Qt::CaseInsensitive ) == 0 )
29322932
return "DWithin";

‎src/plugins/georeferencer/qgsgeorefvalidators.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ QValidator::State QgsDMSAndDDValidator::validate( QString &input, int &pos ) con
5757
rx.setPattern( "-?\\d{1,3}\\s60" );
5858
if ( rx.exactMatch( input ) )
5959
{
60-
int in = input.left( input.indexOf( ' ' ) ).toInt();
60+
int in = input.leftRef( input.indexOf( ' ' ) ).toInt();
6161
int grad = input.startsWith( '-' ) ? in - 1 : in + 1;
6262
if ( grad <= 180 )
6363
input = QString::number( grad );

‎src/providers/grass/qgsgrassprovider.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -525,7 +525,7 @@ int QgsGrassProvider::grassLayer( QString name )
525525
return -1;
526526
}
527527

528-
return name.left( pos ).toInt();
528+
return name.leftRef( pos ).toInt();
529529
}
530530

531531
int QgsGrassProvider::grassLayerType( QString name )

‎src/providers/postgres/qgspostgresprovider.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3852,7 +3852,7 @@ static QString getNextString( const QString& txt, int& i, const QString& sep )
38523852
}
38533853
i += stringRe.cap( 1 ).length() + 2;
38543854
jumpSpace( txt, i );
3855-
if ( !txt.mid( i ).startsWith( sep ) && i < txt.length() )
3855+
if ( !txt.midRef( i ).startsWith( sep ) && i < txt.length() )
38563856
{
38573857
QgsLogger::warning( "Cannot find separator: " + txt.mid( i ) );
38583858
return QString::null;

‎tests/bench/main.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -557,7 +557,7 @@ int main( int argc, char *argv[] )
557557
break;
558558
}
559559

560-
coords[i] = QString( myInitialExtent.mid( posOld, pos - posOld ) ).toDouble( &ok );
560+
coords[i] = myInitialExtent.midRef( posOld, pos - posOld ).toDouble( &ok );
561561
if ( !ok )
562562
break;
563563

@@ -566,7 +566,7 @@ int main( int argc, char *argv[] )
566566

567567
// parse last coordinate
568568
if ( ok )
569-
coords[3] = QString( myInitialExtent.mid( posOld ) ).toDouble( &ok );
569+
coords[3] = myInitialExtent.midRef( posOld ).toDouble( &ok );
570570

571571
if ( !ok )
572572
{

0 commit comments

Comments
 (0)
Please sign in to comment.