Skip to content

Commit

Permalink
Replace toUtf8().data() by toUtf8().constData()
Browse files Browse the repository at this point in the history
All your uses of toUtf8().data() actually just need a const char*
So use constData() that is semantically more correct, and documented
to be faster.

From http://doc.qt.io/qt-5/qbytearray.html#data
"For read-only access, constData() is faster because it never
causes a deep copy to occur."
  • Loading branch information
rouault authored and nyalldawson committed Oct 6, 2018
1 parent f5d2d85 commit 7e81226
Show file tree
Hide file tree
Showing 52 changed files with 100 additions and 100 deletions.
2 changes: 1 addition & 1 deletion python/core/auto_generated/expression/qgsexpression.sip.in
Expand Up @@ -590,7 +590,7 @@ value. The value may be null.
SIP_PYOBJECT __repr__();
%MethodCode
QString str = QStringLiteral( "<QgsExpression: '%1'>" ).arg( sipCpp->expression() );
sipRes = PyUnicode_FromString( str.toUtf8().data() );
sipRes = PyUnicode_FromString( str.toUtf8().constData() );
%End

};
Expand Down
2 changes: 1 addition & 1 deletion python/core/auto_generated/geometry/qgscircle.sip.in
Expand Up @@ -256,7 +256,7 @@ Returns true if the circle contains the ``point``.
SIP_PYOBJECT __repr__();
%MethodCode
QString str = QStringLiteral( "<QgsCircle: %1>" ).arg( sipCpp->toString() );
sipRes = PyUnicode_FromString( str.toUtf8().data() );
sipRes = PyUnicode_FromString( str.toUtf8().constData() );
%End
};

Expand Down
Expand Up @@ -169,7 +169,7 @@ Sets the circular string's points
SIP_PYOBJECT __repr__();
%MethodCode
QString str = QStringLiteral( "<QgsCircularString: %1>" ).arg( sipCpp->asWkt() );
sipRes = PyUnicode_FromString( str.toUtf8().data() );
sipRes = PyUnicode_FromString( str.toUtf8().constData() );
%End

protected:
Expand Down
Expand Up @@ -173,7 +173,7 @@ Appends first point if not already closed.
SIP_PYOBJECT __repr__();
%MethodCode
QString str = QStringLiteral( "<QgsCompoundCurve: %1>" ).arg( sipCpp->asWkt() );
sipRes = PyUnicode_FromString( str.toUtf8().data() );
sipRes = PyUnicode_FromString( str.toUtf8().constData() );
%End

protected:
Expand Down
2 changes: 1 addition & 1 deletion python/core/auto_generated/geometry/qgscurvepolygon.sip.in
Expand Up @@ -219,7 +219,7 @@ Returns approximate rotation angle for a vertex. Usually average angle between a
SIP_PYOBJECT __repr__();
%MethodCode
QString str = QStringLiteral( "<QgsCurvePolygon: %1>" ).arg( sipCpp->asWkt() );
sipRes = PyUnicode_FromString( str.toUtf8().data() );
sipRes = PyUnicode_FromString( str.toUtf8().constData() );
%End

protected:
Expand Down
2 changes: 1 addition & 1 deletion python/core/auto_generated/geometry/qgsellipse.sip.in
Expand Up @@ -251,7 +251,7 @@ Members will be truncated to the specified precision.
SIP_PYOBJECT __repr__();
%MethodCode
QString str = QStringLiteral( "<QgsEllipse: %1>" ).arg( sipCpp->toString() );
sipRes = PyUnicode_FromString( str.toUtf8().data() );
sipRes = PyUnicode_FromString( str.toUtf8().constData() );
%End

protected:
Expand Down
2 changes: 1 addition & 1 deletion python/core/auto_generated/geometry/qgsgeometry.sip.in
Expand Up @@ -1297,7 +1297,7 @@ Exports the geometry to WKT
SIP_PYOBJECT __repr__();
%MethodCode
QString str = QStringLiteral( "<QgsGeometry: %1>" ).arg( sipCpp->asWkt() );
sipRes = PyUnicode_FromString( str.toUtf8().data() );
sipRes = PyUnicode_FromString( str.toUtf8().constData() );
%End

QString asJson( int precision = 17 ) const;
Expand Down
2 changes: 1 addition & 1 deletion python/core/auto_generated/geometry/qgslinestring.sip.in
Expand Up @@ -330,7 +330,7 @@ of the curve.
SIP_PYOBJECT __repr__();
%MethodCode
QString str = QStringLiteral( "<QgsLineString: %1>" ).arg( sipCpp->asWkt() );
sipRes = PyUnicode_FromString( str.toUtf8().data() );
sipRes = PyUnicode_FromString( str.toUtf8().constData() );
%End

protected:
Expand Down
2 changes: 1 addition & 1 deletion python/core/auto_generated/geometry/qgsmulticurve.sip.in
Expand Up @@ -59,7 +59,7 @@ Returns a copy of the multi curve, where each component curve has had its line d
SIP_PYOBJECT __repr__();
%MethodCode
QString str = QStringLiteral( "<QgsMultiCurve: %1>" ).arg( sipCpp->asWkt() );
sipRes = PyUnicode_FromString( str.toUtf8().data() );
sipRes = PyUnicode_FromString( str.toUtf8().constData() );
%End

};
Expand Down
Expand Up @@ -56,7 +56,7 @@ Returns the geometry converted to the more generic curve type :py:class:`QgsMult
SIP_PYOBJECT __repr__();
%MethodCode
QString str = QStringLiteral( "<QgsMultiLineString: %1>" ).arg( sipCpp->asWkt() );
sipRes = PyUnicode_FromString( str.toUtf8().data() );
sipRes = PyUnicode_FromString( str.toUtf8().constData() );
%End

protected:
Expand Down
2 changes: 1 addition & 1 deletion python/core/auto_generated/geometry/qgsmultipoint.sip.in
Expand Up @@ -58,7 +58,7 @@ Multi point geometry collection.
SIP_PYOBJECT __repr__();
%MethodCode
QString str = QStringLiteral( "<QgsMultiPoint: %1>" ).arg( sipCpp->asWkt() );
sipRes = PyUnicode_FromString( str.toUtf8().data() );
sipRes = PyUnicode_FromString( str.toUtf8().constData() );
%End

protected:
Expand Down
2 changes: 1 addition & 1 deletion python/core/auto_generated/geometry/qgsmultipolygon.sip.in
Expand Up @@ -57,7 +57,7 @@ Returns the geometry converted to the more generic curve type :py:class:`QgsMult
SIP_PYOBJECT __repr__();
%MethodCode
QString str = QStringLiteral( "<QgsMultiPolygon: %1>" ).arg( sipCpp->asWkt() );
sipRes = PyUnicode_FromString( str.toUtf8().data() );
sipRes = PyUnicode_FromString( str.toUtf8().constData() );
%End

protected:
Expand Down
2 changes: 1 addition & 1 deletion python/core/auto_generated/geometry/qgspoint.sip.in
Expand Up @@ -429,7 +429,7 @@ Angle undefined. Always returns 0.0
SIP_PYOBJECT __repr__();
%MethodCode
QString str = QStringLiteral( "<QgsPoint: %1>" ).arg( sipCpp->asWkt() );
sipRes = PyUnicode_FromString( str.toUtf8().data() );
sipRes = PyUnicode_FromString( str.toUtf8().constData() );
%End

protected:
Expand Down
2 changes: 1 addition & 1 deletion python/core/auto_generated/geometry/qgspolygon.sip.in
Expand Up @@ -68,7 +68,7 @@ negative if the point lies outside the polygon.
SIP_PYOBJECT __repr__();
%MethodCode
QString str = QStringLiteral( "<QgsPolygon: %1>" ).arg( sipCpp->asWkt() );
sipRes = PyUnicode_FromString( str.toUtf8().data() );
sipRes = PyUnicode_FromString( str.toUtf8().constData() );
%End

protected:
Expand Down
2 changes: 1 addition & 1 deletion python/core/auto_generated/geometry/qgsrectangle.sip.in
Expand Up @@ -325,7 +325,7 @@ Converts the rectangle to a 3D box, with the specified
SIP_PYOBJECT __repr__();
%MethodCode
QString str = QStringLiteral( "<QgsRectangle: %1>" ).arg( sipCpp->asWktCoordinates() );
sipRes = PyUnicode_FromString( str.toUtf8().data() );
sipRes = PyUnicode_FromString( str.toUtf8().constData() );
%End

};
Expand Down
2 changes: 1 addition & 1 deletion python/core/auto_generated/qgsfield.sip.in
Expand Up @@ -333,7 +333,7 @@ by manual field configuration.
SIP_PYOBJECT __repr__();
%MethodCode
QString str = QStringLiteral( "<QgsField: %1 (%2)>" ).arg( sipCpp->name() ).arg( sipCpp->typeName() );
sipRes = PyUnicode_FromString( str.toUtf8().data() );
sipRes = PyUnicode_FromString( str.toUtf8().constData() );
%End

}; // class QgsField
Expand Down
2 changes: 1 addition & 1 deletion python/core/auto_generated/qgspointxy.sip.in
Expand Up @@ -231,7 +231,7 @@ Multiply x and y by the given value
SIP_PYOBJECT __repr__();
%MethodCode
QString str = QStringLiteral( "<QgsPointXY: %1>" ).arg( sipCpp->asWkt() );
sipRes = PyUnicode_FromString( str.toUtf8().data() );
sipRes = PyUnicode_FromString( str.toUtf8().constData() );
%End

int __len__();
Expand Down
2 changes: 1 addition & 1 deletion src/app/qgisapp.cpp
Expand Up @@ -10534,7 +10534,7 @@ void QgisApp::openURL( QString url, bool useQgisDocDirectory )
* commandline application rather than a bundled application.
*/
CFURLRef urlRef = CFURLCreateWithBytes( kCFAllocatorDefault,
reinterpret_cast<const UInt8 *>( url.toUtf8().data() ), url.length(),
reinterpret_cast<const UInt8 *>( url.toUtf8().constData() ), url.length(),
kCFStringEncodingUTF8, nullptr );
OSStatus status = LSOpenCFURLRef( urlRef, nullptr );
status = 0; //avoid compiler warning
Expand Down
2 changes: 1 addition & 1 deletion src/core/expression/qgsexpression.h
Expand Up @@ -614,7 +614,7 @@ class CORE_EXPORT QgsExpression
SIP_PYOBJECT __repr__();
% MethodCode
QString str = QStringLiteral( "<QgsExpression: '%1'>" ).arg( sipCpp->expression() );
sipRes = PyUnicode_FromString( str.toUtf8().data() );
sipRes = PyUnicode_FromString( str.toUtf8().constData() );
% End
#endif

Expand Down
2 changes: 1 addition & 1 deletion src/core/geometry/qgscircle.h
Expand Up @@ -251,7 +251,7 @@ class CORE_EXPORT QgsCircle : public QgsEllipse
SIP_PYOBJECT __repr__();
% MethodCode
QString str = QStringLiteral( "<QgsCircle: %1>" ).arg( sipCpp->toString() );
sipRes = PyUnicode_FromString( str.toUtf8().data() );
sipRes = PyUnicode_FromString( str.toUtf8().constData() );
% End
#endif
};
Expand Down
2 changes: 1 addition & 1 deletion src/core/geometry/qgscircularstring.h
Expand Up @@ -153,7 +153,7 @@ class CORE_EXPORT QgsCircularString: public QgsCurve
SIP_PYOBJECT __repr__();
% MethodCode
QString str = QStringLiteral( "<QgsCircularString: %1>" ).arg( sipCpp->asWkt() );
sipRes = PyUnicode_FromString( str.toUtf8().data() );
sipRes = PyUnicode_FromString( str.toUtf8().constData() );
% End
#endif

Expand Down
2 changes: 1 addition & 1 deletion src/core/geometry/qgscompoundcurve.h
Expand Up @@ -153,7 +153,7 @@ class CORE_EXPORT QgsCompoundCurve: public QgsCurve
SIP_PYOBJECT __repr__();
% MethodCode
QString str = QStringLiteral( "<QgsCompoundCurve: %1>" ).arg( sipCpp->asWkt() );
sipRes = PyUnicode_FromString( str.toUtf8().data() );
sipRes = PyUnicode_FromString( str.toUtf8().constData() );
% End
#endif

Expand Down
2 changes: 1 addition & 1 deletion src/core/geometry/qgscurvepolygon.h
Expand Up @@ -209,7 +209,7 @@ class CORE_EXPORT QgsCurvePolygon: public QgsSurface
SIP_PYOBJECT __repr__();
% MethodCode
QString str = QStringLiteral( "<QgsCurvePolygon: %1>" ).arg( sipCpp->asWkt() );
sipRes = PyUnicode_FromString( str.toUtf8().data() );
sipRes = PyUnicode_FromString( str.toUtf8().constData() );
% End
#endif

Expand Down
2 changes: 1 addition & 1 deletion src/core/geometry/qgsellipse.h
Expand Up @@ -244,7 +244,7 @@ class CORE_EXPORT QgsEllipse
SIP_PYOBJECT __repr__();
% MethodCode
QString str = QStringLiteral( "<QgsEllipse: %1>" ).arg( sipCpp->toString() );
sipRes = PyUnicode_FromString( str.toUtf8().data() );
sipRes = PyUnicode_FromString( str.toUtf8().constData() );
% End
#endif

Expand Down
2 changes: 1 addition & 1 deletion src/core/geometry/qgsgeometry.h
Expand Up @@ -1256,7 +1256,7 @@ class CORE_EXPORT QgsGeometry
SIP_PYOBJECT __repr__();
% MethodCode
QString str = QStringLiteral( "<QgsGeometry: %1>" ).arg( sipCpp->asWkt() );
sipRes = PyUnicode_FromString( str.toUtf8().data() );
sipRes = PyUnicode_FromString( str.toUtf8().constData() );
% End
#endif

Expand Down
2 changes: 1 addition & 1 deletion src/core/geometry/qgslinestring.h
Expand Up @@ -360,7 +360,7 @@ class CORE_EXPORT QgsLineString: public QgsCurve
SIP_PYOBJECT __repr__();
% MethodCode
QString str = QStringLiteral( "<QgsLineString: %1>" ).arg( sipCpp->asWkt() );
sipRes = PyUnicode_FromString( str.toUtf8().data() );
sipRes = PyUnicode_FromString( str.toUtf8().constData() );
% End
#endif

Expand Down
2 changes: 1 addition & 1 deletion src/core/geometry/qgsmulticurve.h
Expand Up @@ -77,7 +77,7 @@ class CORE_EXPORT QgsMultiCurve: public QgsGeometryCollection
SIP_PYOBJECT __repr__();
% MethodCode
QString str = QStringLiteral( "<QgsMultiCurve: %1>" ).arg( sipCpp->asWkt() );
sipRes = PyUnicode_FromString( str.toUtf8().data() );
sipRes = PyUnicode_FromString( str.toUtf8().constData() );
% End
#endif

Expand Down
2 changes: 1 addition & 1 deletion src/core/geometry/qgsmultilinestring.h
Expand Up @@ -69,7 +69,7 @@ class CORE_EXPORT QgsMultiLineString: public QgsMultiCurve
SIP_PYOBJECT __repr__();
% MethodCode
QString str = QStringLiteral( "<QgsMultiLineString: %1>" ).arg( sipCpp->asWkt() );
sipRes = PyUnicode_FromString( str.toUtf8().data() );
sipRes = PyUnicode_FromString( str.toUtf8().constData() );
% End
#endif

Expand Down
2 changes: 1 addition & 1 deletion src/core/geometry/qgsmultipoint.h
Expand Up @@ -70,7 +70,7 @@ class CORE_EXPORT QgsMultiPoint: public QgsGeometryCollection
SIP_PYOBJECT __repr__();
% MethodCode
QString str = QStringLiteral( "<QgsMultiPoint: %1>" ).arg( sipCpp->asWkt() );
sipRes = PyUnicode_FromString( str.toUtf8().data() );
sipRes = PyUnicode_FromString( str.toUtf8().constData() );
% End
#endif

Expand Down
2 changes: 1 addition & 1 deletion src/core/geometry/qgsmultipolygon.h
Expand Up @@ -69,7 +69,7 @@ class CORE_EXPORT QgsMultiPolygon: public QgsMultiSurface
SIP_PYOBJECT __repr__();
% MethodCode
QString str = QStringLiteral( "<QgsMultiPolygon: %1>" ).arg( sipCpp->asWkt() );
sipRes = PyUnicode_FromString( str.toUtf8().data() );
sipRes = PyUnicode_FromString( str.toUtf8().constData() );
% End
#endif

Expand Down
2 changes: 1 addition & 1 deletion src/core/geometry/qgspoint.h
Expand Up @@ -500,7 +500,7 @@ class CORE_EXPORT QgsPoint: public QgsAbstractGeometry
SIP_PYOBJECT __repr__();
% MethodCode
QString str = QStringLiteral( "<QgsPoint: %1>" ).arg( sipCpp->asWkt() );
sipRes = PyUnicode_FromString( str.toUtf8().data() );
sipRes = PyUnicode_FromString( str.toUtf8().constData() );
% End
#endif

Expand Down
2 changes: 1 addition & 1 deletion src/core/geometry/qgspolygon.h
Expand Up @@ -88,7 +88,7 @@ class CORE_EXPORT QgsPolygon: public QgsCurvePolygon
SIP_PYOBJECT __repr__();
% MethodCode
QString str = QStringLiteral( "<QgsPolygon: %1>" ).arg( sipCpp->asWkt() );
sipRes = PyUnicode_FromString( str.toUtf8().data() );
sipRes = PyUnicode_FromString( str.toUtf8().constData() );
% End
#endif

Expand Down
2 changes: 1 addition & 1 deletion src/core/geometry/qgsrectangle.h
Expand Up @@ -545,7 +545,7 @@ class CORE_EXPORT QgsRectangle
SIP_PYOBJECT __repr__();
% MethodCode
QString str = QStringLiteral( "<QgsRectangle: %1>" ).arg( sipCpp->asWktCoordinates() );
sipRes = PyUnicode_FromString( str.toUtf8().data() );
sipRes = PyUnicode_FromString( str.toUtf8().constData() );
% End
#endif

Expand Down
6 changes: 3 additions & 3 deletions src/core/qgsapplication.cpp
Expand Up @@ -666,11 +666,11 @@ QString QgsApplication::resolvePkgPath()
ABISYM( mBuildSourcePath ) = f.readLine().trimmed();
ABISYM( mBuildOutputPath ) = f.readLine().trimmed();
QgsDebugMsgLevel( QStringLiteral( "Running from build directory!" ), 4 );
QgsDebugMsgLevel( QStringLiteral( "- source directory: %1" ).arg( ABISYM( mBuildSourcePath ).toUtf8().data() ), 4 );
QgsDebugMsgLevel( QStringLiteral( "- output directory of the build: %1" ).arg( ABISYM( mBuildOutputPath ).toUtf8().data() ), 4 );
QgsDebugMsgLevel( QStringLiteral( "- source directory: %1" ).arg( ABISYM( mBuildSourcePath ).toUtf8().constData() ), 4 );
QgsDebugMsgLevel( QStringLiteral( "- output directory of the build: %1" ).arg( ABISYM( mBuildOutputPath ).toUtf8().constData() ), 4 );
#if defined(_MSC_VER) && !defined(USING_NMAKE) && !defined(USING_NINJA)
ABISYM( mCfgIntDir ) = appPath.split( '/', QString::SkipEmptyParts ).last();
qDebug( "- cfg: %s", ABISYM( mCfgIntDir ).toUtf8().data() );
qDebug( "- cfg: %s", ABISYM( mCfgIntDir ).toUtf8().constData() );
#endif
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/core/qgsfield.h
Expand Up @@ -339,7 +339,7 @@ class CORE_EXPORT QgsField
SIP_PYOBJECT __repr__();
% MethodCode
QString str = QStringLiteral( "<QgsField: %1 (%2)>" ).arg( sipCpp->name() ).arg( sipCpp->typeName() );
sipRes = PyUnicode_FromString( str.toUtf8().data() );
sipRes = PyUnicode_FromString( str.toUtf8().constData() );
% End
#endif

Expand Down
2 changes: 1 addition & 1 deletion src/core/qgspointxy.h
Expand Up @@ -298,7 +298,7 @@ class CORE_EXPORT QgsPointXY
SIP_PYOBJECT __repr__();
% MethodCode
QString str = QStringLiteral( "<QgsPointXY: %1>" ).arg( sipCpp->asWkt() );
sipRes = PyUnicode_FromString( str.toUtf8().data() );
sipRes = PyUnicode_FromString( str.toUtf8().constData() );
% End

int __len__();
Expand Down
2 changes: 1 addition & 1 deletion src/core/qgsxmlutils.h
Expand Up @@ -97,7 +97,7 @@ class CORE_EXPORT QgsXmlUtils
if ( metaEnum.isValid() )
{
bool ok = false;
int newValue = metaEnum.keysToValue( sourceCategoriesStr.toUtf8().data(), &ok );
int newValue = metaEnum.keysToValue( sourceCategoriesStr.toUtf8().constData(), &ok );
if ( ok )
value = static_cast<T>( newValue );
}
Expand Down
4 changes: 2 additions & 2 deletions src/crashhandler/main.cpp
Expand Up @@ -42,7 +42,7 @@ int main( int argc, char *argv[] )
QCoreApplication::setApplicationName( "QGIS3" );

QString extraInfoFile = QString( argv[1] );
std::cout << "Extra Info File: " << extraInfoFile.toUtf8().data() << std::endl;
std::cout << "Extra Info File: " << extraInfoFile.toUtf8().constData() << std::endl;

QFile file( extraInfoFile );
QString processIdString;
Expand Down Expand Up @@ -75,7 +75,7 @@ int main( int argc, char *argv[] )
std::cout << "Process ID: " << processIdString.toLocal8Bit().constData() << std::endl;
std::cout << "Thread ID:" << threadIdString.toLocal8Bit().constData() << std::endl;
std::cout << "Exception Pointer: " << exceptionPointersString.toLocal8Bit().constData() << std::endl;
std::cout << "Symbol Path :" << symbolPaths.toUtf8().data() << std::endl;
std::cout << "Symbol Path :" << symbolPaths.toUtf8().constData() << std::endl;

std::unique_ptr<QgsStackTrace> stackTrace( QgsStackTrace::trace( processId, threadId, exception, symbolPaths ) );

Expand Down

0 comments on commit 7e81226

Please sign in to comment.