Skip to content
Permalink
Browse files

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
  • Loading branch information
nyalldawson committed Oct 22, 2016
1 parent a51bebd commit ef5110732b79e8e4addd1c974d18c48d9ad61fc1
@@ -1126,7 +1126,7 @@ int main( int argc, char *argv[] )
break;
}

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

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

// parse last coordinate
if ( ok )
coords[3] = QString( myInitialExtent.mid( posOld ) ).toDouble( &ok );
coords[3] = myInitialExtent.midRef( posOld ).toDouble( &ok );

if ( !ok )
{
@@ -1908,14 +1908,14 @@ void QgsProjectProperties::populateEllipsoidList()
// Crash if no column?
para1 = ( const char * )sqlite3_column_text( myPreparedStatement, 2 );
para2 = ( const char * )sqlite3_column_text( myPreparedStatement, 3 );
myItem.semiMajor = para1.mid( 2 ).toDouble();
myItem.semiMajor = para1.midRef( 2 ).toDouble();
if ( para2.left( 2 ) == "b=" )
{
myItem.semiMinor = para2.mid( 2 ).toDouble();
myItem.semiMinor = para2.midRef( 2 ).toDouble();
}
else if ( para2.left( 3 ) == "rf=" )
{
double invFlattening = para2.mid( 3 ).toDouble();
double invFlattening = para2.midRef( 3 ).toDouble();
if ( invFlattening != 0.0 )
{
myItem.semiMinor = myItem.semiMajor - ( myItem.semiMajor / invFlattening );
@@ -72,7 +72,7 @@ QgsColorRamp* QgsGradientColorRamp::create( const QgsStringMap& props )
continue;

QColor c = QgsSymbolLayerUtils::decodeColor( stop.mid( i + 1 ) );
stops.append( QgsGradientStop( stop.left( i ).toDouble(), c ) );
stops.append( QgsGradientStop( stop.leftRef( i ).toDouble(), c ) );
}
}

@@ -500,7 +500,7 @@ bool QgsCoordinateReferenceSystem::hasAxisInverted() const
{
OGRSpatialReferenceH crs = OSRNewSpatialReference( nullptr );

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

bool ok;
int epsg = line.left( pos ).toInt( &ok );
int epsg = line.leftRef( pos ).toInt( &ok );
if ( !ok )
return false;

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

bool ok;
int epsg = line.left( pos ).toInt( &ok );
int epsg = line.leftRef( pos ).toInt( &ok );
if ( !ok )
continue;

@@ -191,7 +191,7 @@ bool QgsDistanceArea::setEllipsoid( const QString& ellipsoid )

// get major semiaxis
if ( radius.left( 2 ) == "a=" )
mSemiMajor = radius.mid( 2 ).toDouble();
mSemiMajor = radius.midRef( 2 ).toDouble();
else
{
QgsDebugMsg( QString( "setEllipsoid: wrong format of radius field: '%1'" ).arg( radius ) );
@@ -203,12 +203,12 @@ bool QgsDistanceArea::setEllipsoid( const QString& ellipsoid )
// second one must be computed using formula: invf = a/(a-b)
if ( parameter2.left( 2 ) == "b=" )
{
mSemiMinor = parameter2.mid( 2 ).toDouble();
mSemiMinor = parameter2.midRef( 2 ).toDouble();
mInvFlattening = mSemiMajor / ( mSemiMajor - mSemiMinor );
}
else if ( parameter2.left( 3 ) == "rf=" )
{
mInvFlattening = parameter2.mid( 3 ).toDouble();
mInvFlattening = parameter2.midRef( 3 ).toDouble();
mSemiMinor = mSemiMajor - ( mSemiMajor / mInvFlattening );
}
else
@@ -2910,7 +2910,7 @@ QDomElement QgsOgcUtilsSQLStatementToFilter::toOgcFilter( const QgsSQLStatement:
static QString mapBinarySpatialToOgc( const QString& name )
{
QString nameCompare( name );
if ( name.size() > 3 && name.mid( 0, 3 ).compare( "ST_", Qt::CaseInsensitive ) == 0 )
if ( name.size() > 3 && name.midRef( 0, 3 ).compare( "ST_", Qt::CaseInsensitive ) == 0 )
nameCompare = name.mid( 3 );
QStringList spatialOps;
spatialOps << "BBOX" << "Intersects" << "Contains" << "Crosses" << "Equals"
@@ -2926,7 +2926,7 @@ static QString mapBinarySpatialToOgc( const QString& name )
static QString mapTernarySpatialToOgc( const QString& name )
{
QString nameCompare( name );
if ( name.size() > 3 && name.mid( 0, 3 ).compare( "ST_", Qt::CaseInsensitive ) == 0 )
if ( name.size() > 3 && name.midRef( 0, 3 ).compare( "ST_", Qt::CaseInsensitive ) == 0 )
nameCompare = name.mid( 3 );
if ( nameCompare.compare( "DWithin", Qt::CaseInsensitive ) == 0 )
return "DWithin";
@@ -57,7 +57,7 @@ QValidator::State QgsDMSAndDDValidator::validate( QString &input, int &pos ) con
rx.setPattern( "-?\\d{1,3}\\s60" );
if ( rx.exactMatch( input ) )
{
int in = input.left( input.indexOf( ' ' ) ).toInt();
int in = input.leftRef( input.indexOf( ' ' ) ).toInt();
int grad = input.startsWith( '-' ) ? in - 1 : in + 1;
if ( grad <= 180 )
input = QString::number( grad );
@@ -525,7 +525,7 @@ int QgsGrassProvider::grassLayer( QString name )
return -1;
}

return name.left( pos ).toInt();
return name.leftRef( pos ).toInt();
}

int QgsGrassProvider::grassLayerType( QString name )
@@ -3852,7 +3852,7 @@ static QString getNextString( const QString& txt, int& i, const QString& sep )
}
i += stringRe.cap( 1 ).length() + 2;
jumpSpace( txt, i );
if ( !txt.mid( i ).startsWith( sep ) && i < txt.length() )
if ( !txt.midRef( i ).startsWith( sep ) && i < txt.length() )
{
QgsLogger::warning( "Cannot find separator: " + txt.mid( i ) );
return QString::null;
@@ -557,7 +557,7 @@ int main( int argc, char *argv[] )
break;
}

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

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

// parse last coordinate
if ( ok )
coords[3] = QString( myInitialExtent.mid( posOld ) ).toDouble( &ok );
coords[3] = myInitialExtent.midRef( posOld ).toDouble( &ok );

if ( !ok )
{

0 comments on commit ef51107

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