diff options
author | Marc Mutz <marc.mutz@kdab.com> | 2016-05-09 13:18:20 +0200 |
---|---|---|
committer | Sean Harmer <sean.harmer@kdab.com> | 2016-05-14 16:02:05 +0000 |
commit | 8ac9e30bb13ee09de71fe07ca85d89d8f6605da9 (patch) | |
tree | a465d6d12e931fa84025d9d62d830421172aa714 /src | |
parent | be27013007267f3a5d3eb518fb75580c5d451cff (diff) |
Qt3D: replace QStringLiteral with QLatin1String when appending or comparing
It makes little sense to use QStringLiteral in the following
situations:
- for comparison to a QString, because operator== is overloaded
for QLatin1String.
- when constructing an empty QString, because QLatin1String("")
resolves to sharedEmpty() when converted to QString, which is
preferable to an independent copy of sharedEmpty().
- for strings which are immediately appended to, or which are
appended to other strings.
because no dynamic memory allocation is saved by doing so. But if
the only advantage of QStringLiteral does not apply, all its
disadvantages dominate, to wit: injection of calls to the qstring
dtor, non-sharability of data between C strings and QStringLiterals
and among QStringLiterals, and doubled storage requirements.
Fix by replacing QStringLiteral with QLatin1String or QLatin1Char,
as needed.
Ported one use of QString::number(i) to QLatin1Char('0' + i) where
i is guaranteed to be < 10.
Saves 179B and 2150B, resp., in Input and Render text size on
optimized Linux AMD64 GCC 6.0 builds.
Change-Id: I2e8f43ed085875ce387ffddb18bba37ff21f6cf0
Reviewed-by: Sean Harmer <sean.harmer@kdab.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/input/frontend/qmousedevice.cpp | 4 | ||||
-rw-r--r-- | src/quick3d/imports/core/qt3dquick3dcoreplugin.cpp | 2 | ||||
-rw-r--r-- | src/quick3d/imports/extras/qt3dquick3dextrasplugin.cpp | 4 | ||||
-rw-r--r-- | src/quick3d/imports/scene3d/scene3ditem.cpp | 4 | ||||
-rw-r--r-- | src/render/backend/renderview.cpp | 11 | ||||
-rw-r--r-- | src/render/io/objloader.cpp | 2 | ||||
-rw-r--r-- | src/render/io/qsceneiofactory.cpp | 2 | ||||
-rw-r--r-- | src/render/jobs/renderviewjobutils.cpp | 10 | ||||
-rw-r--r-- | src/render/materialsystem/qshaderprogram.cpp | 4 | ||||
-rw-r--r-- | src/render/materialsystem/shader.cpp | 2 | ||||
-rw-r--r-- | src/render/materialsystem/shaderdata.cpp | 2 | ||||
-rw-r--r-- | src/render/texture/qtextureimage_p.h | 2 | ||||
-rw-r--r-- | src/render/texture/qtextureimagedata.cpp | 4 |
13 files changed, 27 insertions, 26 deletions
diff --git a/src/input/frontend/qmousedevice.cpp b/src/input/frontend/qmousedevice.cpp index 49e925a49..40e5df47c 100644 --- a/src/input/frontend/qmousedevice.cpp +++ b/src/input/frontend/qmousedevice.cpp @@ -104,9 +104,9 @@ QStringList QMouseDevice::buttonNames() const int QMouseDevice::axisIdentifier(const QString &name) const { - if (name == QStringLiteral("X")) + if (name == QLatin1String("X")) return X; - else if (name == QStringLiteral("Y")) + else if (name == QLatin1String("Y")) return Y; return -1; } diff --git a/src/quick3d/imports/core/qt3dquick3dcoreplugin.cpp b/src/quick3d/imports/core/qt3dquick3dcoreplugin.cpp index 098b8a131..b72ee9600 100644 --- a/src/quick3d/imports/core/qt3dquick3dcoreplugin.cpp +++ b/src/quick3d/imports/core/qt3dquick3dcoreplugin.cpp @@ -52,7 +52,7 @@ void Qt3DQuick3DCorePlugin::registerTypes(const char *uri) { Qt3DCore::Quick::Quick3D_initialize(); - qmlRegisterUncreatableType<Qt3DCore::QComponent>(uri, 2, 0, "Component3D", QStringLiteral("")); + qmlRegisterUncreatableType<Qt3DCore::QComponent>(uri, 2, 0, "Component3D", QLatin1String("")); Qt3DCore::Quick::registerExtendedType<Qt3DCore::QEntity, Qt3DCore::Quick::Quick3DEntity>("QEntity", "Qt3D.Core/Entity", uri, 2, 0, "Entity"); qmlRegisterType<Qt3DCore::Quick::Quick3DEntityLoader>(uri, 2, 0, "EntityLoader"); diff --git a/src/quick3d/imports/extras/qt3dquick3dextrasplugin.cpp b/src/quick3d/imports/extras/qt3dquick3dextrasplugin.cpp index aa65c8b65..c9e3cdfc9 100644 --- a/src/quick3d/imports/extras/qt3dquick3dextrasplugin.cpp +++ b/src/quick3d/imports/extras/qt3dquick3dextrasplugin.cpp @@ -97,8 +97,8 @@ void Qt3DQuick3DExtrasPlugin::registerTypes(const char *uri) // Register types provided as QML files compiled into the plugin for (int i = 0; i < int(sizeof(qmldir) / sizeof(qmldir[0])); i++) { - QString path = QStringLiteral("qrc:/qt-project.org/imports/Qt3D/Extras/defaults/qml/"); - qmlRegisterType(QUrl(path + qmldir[i].type + QStringLiteral(".qml")), + auto path = QLatin1String("qrc:/qt-project.org/imports/Qt3D/Extras/defaults/qml/"); + qmlRegisterType(QUrl(path + qmldir[i].type + QLatin1String(".qml")), uri, qmldir[i].major, qmldir[i].minor, qmldir[i].type); diff --git a/src/quick3d/imports/scene3d/scene3ditem.cpp b/src/quick3d/imports/scene3d/scene3ditem.cpp index 5ec76f10a..42fcd1771 100644 --- a/src/quick3d/imports/scene3d/scene3ditem.cpp +++ b/src/quick3d/imports/scene3d/scene3ditem.cpp @@ -114,9 +114,9 @@ void Scene3DItem::setAspects(const QStringList &aspects) // Aspects are owned by the aspect engine Q_FOREACH (const QString &aspect, m_aspects) { - if (aspect == QStringLiteral("render")) // This one is hardwired anyway + if (aspect == QLatin1String("render")) // This one is hardwired anyway continue; - if (aspect == QStringLiteral("input")) { + if (aspect == QLatin1String("input")) { m_aspectEngine->registerAspect(new Qt3DInput::QInputAspect); continue; } diff --git a/src/render/backend/renderview.cpp b/src/render/backend/renderview.cpp index 932d0c880..358754dbd 100644 --- a/src/render/backend/renderview.cpp +++ b/src/render/backend/renderview.cpp @@ -88,10 +88,10 @@ const int qNodeIdTypeId = qMetaTypeId<Qt3DCore::QNodeId>(); const int MAX_LIGHTS = 8; -const QString LIGHT_POSITION_NAME = QStringLiteral(".position"); -const QString LIGHT_TYPE_NAME = QStringLiteral(".type"); -const QString LIGHT_COLOR_NAME = QStringLiteral(".color"); -const QString LIGHT_INTENSITY_NAME = QStringLiteral(".intensity"); +#define LIGHT_POSITION_NAME QLatin1String(".position") +#define LIGHT_TYPE_NAME QLatin1String(".type") +#define LIGHT_COLOR_NAME QLatin1String(".color") +#define LIGHT_INTENSITY_NAME QLatin1String(".intensity") int LIGHT_COUNT_NAME_ID = 0; int LIGHT_POSITION_NAMES[MAX_LIGHTS]; @@ -290,7 +290,8 @@ RenderView::RenderView() RenderView::ms_standardUniformSetters = RenderView::initializeStandardUniformSetters(); LIGHT_COUNT_NAME_ID = StringToInt::lookupId(QStringLiteral("lightCount")); for (int i = 0; i < MAX_LIGHTS; ++i) { - LIGHT_STRUCT_NAMES[i] = QStringLiteral("lights[") + QString::number(i) + QLatin1Char(']'); + Q_STATIC_ASSERT_X(MAX_LIGHTS < 10, "can't use the QChar trick anymore"); + LIGHT_STRUCT_NAMES[i] = QLatin1String("lights[") + QLatin1Char(char('0' + i)) + QLatin1Char(']'); LIGHT_POSITION_NAMES[i] = StringToInt::lookupId(LIGHT_STRUCT_NAMES[i] + LIGHT_POSITION_NAME); LIGHT_TYPE_NAMES[i] = StringToInt::lookupId(LIGHT_STRUCT_NAMES[i] + LIGHT_TYPE_NAME); LIGHT_COLOR_NAMES[i] = StringToInt::lookupId(LIGHT_STRUCT_NAMES[i] + LIGHT_COLOR_NAME); diff --git a/src/render/io/objloader.cpp b/src/render/io/objloader.cpp index a5fe930db..b15e84de8 100644 --- a/src/render/io/objloader.cpp +++ b/src/render/io/objloader.cpp @@ -195,7 +195,7 @@ bool ObjLoader::load(::QIODevice *ioDev, const QString &subMesh) QRegExp subMeshMatch(subMesh); if (!subMeshMatch.isValid()) - subMeshMatch.setPattern(QString(QStringLiteral("^(%1)$")).arg(subMesh)); + subMeshMatch.setPattern(QLatin1String("^(") + subMesh + QLatin1String(")$")); Q_ASSERT(subMeshMatch.isValid()); char lineBuffer[1024]; diff --git a/src/render/io/qsceneiofactory.cpp b/src/render/io/qsceneiofactory.cpp index a32c1e16f..5044d3bd2 100644 --- a/src/render/io/qsceneiofactory.cpp +++ b/src/render/io/qsceneiofactory.cpp @@ -62,7 +62,7 @@ QStringList QSceneIOFactory::keys(const QString &pluginPath) QCoreApplication::addLibraryPath(pluginPath); list = directLoader()->keyMap().values(); if (!list.isEmpty()) { - const QString postFix = QStringLiteral(" (from ") + const QString postFix = QLatin1String(" (from ") + QDir::toNativeSeparators(pluginPath) + QLatin1Char(')'); const QStringList::iterator end = list.end(); diff --git a/src/render/jobs/renderviewjobutils.cpp b/src/render/jobs/renderviewjobutils.cpp index e629497bf..28d6e457e 100644 --- a/src/render/jobs/renderviewjobutils.cpp +++ b/src/render/jobs/renderviewjobutils.cpp @@ -428,12 +428,12 @@ void UniformBlockValueBuilder::buildActiveUniformNameValueMapHelper(const QStrin ShaderData *subShaderData = shaderDataManager->lookupResource(list.at(i).value<QNodeId>()); if (subShaderData) buildActiveUniformNameValueMapStructHelper(subShaderData, - blockName + QStringLiteral(".") + qmlPropertyName + blockArray.arg(i), - QStringLiteral("")); + blockName + QLatin1Char('.') + qmlPropertyName + blockArray.arg(i), + QLatin1String("")); } } } else { // Array of scalar/vec qmlPropertyName[0] - QString varName = blockName + QStringLiteral(".") + qmlPropertyName + QStringLiteral("[0]"); + QString varName = blockName + QLatin1String(".") + qmlPropertyName + QLatin1String("[0]"); if (uniforms.contains(varName)) { qCDebug(Shaders) << "UBO array member " << varName << " set for update"; activeUniformNamesToValue.insert(StringToInt::lookupId(varName), value); @@ -446,7 +446,7 @@ void UniformBlockValueBuilder::buildActiveUniformNameValueMapHelper(const QStrin blockName, qmlPropertyName); } else { // Scalar / Vec - QString varName = blockName + QStringLiteral(".") + qmlPropertyName; + QString varName = blockName + QLatin1Char('.') + qmlPropertyName; if (uniforms.contains(varName)) { qCDebug(Shaders) << "UBO scalar member " << varName << " set for update"; activeUniformNamesToValue.insert(StringToInt::lookupId(varName), value); @@ -461,7 +461,7 @@ void UniformBlockValueBuilder::buildActiveUniformNameValueMapStructHelper(Shader const QHash<QString, QVariant>::const_iterator end = properties.end(); while (it != end) { - QString prefix = qmlPropertyName.isEmpty() ? QStringLiteral("") : QStringLiteral("."); + const auto prefix = qmlPropertyName.isEmpty() ? QLatin1String("") : QLatin1String("."); buildActiveUniformNameValueMapHelper(blockName + prefix + qmlPropertyName, it.key(), it.value()); diff --git a/src/render/materialsystem/qshaderprogram.cpp b/src/render/materialsystem/qshaderprogram.cpp index 75ca03c78..abfbdd4db 100644 --- a/src/render/materialsystem/qshaderprogram.cpp +++ b/src/render/materialsystem/qshaderprogram.cpp @@ -223,10 +223,10 @@ static QByteArray deincludify(const QString &filePath) for (int i = 0; i < lines.count(); ++i) { if (lines[i].startsWith(includeDirective)) { QString includeFileName = QFileInfo(filePath).absolutePath() - + QStringLiteral("/") + + QLatin1Char('/') + QString::fromUtf8(lines[i].mid(includeDirective.count() + 1)); if (qEnvironmentVariableIsSet("QT3D_GLSL100_WORKAROUND")) { - QString candidate = includeFileName + QStringLiteral("100"); + QString candidate = includeFileName + QLatin1String("100"); if (QFile::exists(candidate)) includeFileName = candidate; } diff --git a/src/render/materialsystem/shader.cpp b/src/render/materialsystem/shader.cpp index 67c9a0da6..b048909f1 100644 --- a/src/render/materialsystem/shader.cpp +++ b/src/render/materialsystem/shader.cpp @@ -408,7 +408,7 @@ void Shader::initializeUniformBlocks(const QVector<ShaderUniformBlock> &uniformB if (uniformsIt->m_blockIndex == uniformBlockDescription[i].m_index) { QString uniformName = *uniformNamesIt; if (!m_uniformBlockNames[i].isEmpty() && !uniformName.startsWith(m_uniformBlockNames[i])) - uniformName = m_uniformBlockNames[i] + QStringLiteral(".") + *uniformNamesIt; + uniformName = m_uniformBlockNames[i] + QLatin1Char('.') + *uniformNamesIt; activeUniformsInBlock.insert(uniformName, *uniformsIt); qCDebug(Shaders) << "Active Uniform Block " << uniformName << " in block " << m_uniformBlockNames[i] << " at index " << uniformsIt->m_blockIndex; } diff --git a/src/render/materialsystem/shaderdata.cpp b/src/render/materialsystem/shaderdata.cpp index ee7893e7c..27802bb93 100644 --- a/src/render/materialsystem/shaderdata.cpp +++ b/src/render/materialsystem/shaderdata.cpp @@ -304,7 +304,7 @@ void ShaderData::readPeerProperties(QShaderData *shaderData) while (it != end) { if (static_cast<QMetaType::Type>(it.value().type()) == QMetaType::QVector3D) { // if there is a matching QShaderData::TransformType propertyTransformed - QVariant value = m_properties.value(it.key() + QStringLiteral("Transformed")); + QVariant value = m_properties.value(it.key() + QLatin1String("Transformed")); // if that's the case, we apply a space transformation to the property if (value.isValid() && value.type() == QVariant::Int) m_transformedProperties.insert(it.key(), static_cast<TransformType>(value.toInt())); diff --git a/src/render/texture/qtextureimage_p.h b/src/render/texture/qtextureimage_p.h index ae82f6873..15b402525 100644 --- a/src/render/texture/qtextureimage_p.h +++ b/src/render/texture/qtextureimage_p.h @@ -86,7 +86,7 @@ public: QTextureImageDataPtr operator ()() Q_DECL_FINAL { QTextureImageDataPtr dataPtr; - if (m_url.isLocalFile() || m_url.scheme() == QStringLiteral("qrc")) { + if (m_url.isLocalFile() || m_url.scheme() == QLatin1String("qrc")) { QString source = Qt3DRender::QUrlHelper::urlToLocalFileOrQrc(m_url); dataPtr.reset(new QTextureImageData()); if (dataPtr->setCompressedFile(source)) diff --git a/src/render/texture/qtextureimagedata.cpp b/src/render/texture/qtextureimagedata.cpp index 5b82bae1a..ff4e7198f 100644 --- a/src/render/texture/qtextureimagedata.cpp +++ b/src/render/texture/qtextureimagedata.cpp @@ -453,9 +453,9 @@ bool QTextureImageDataPrivate::setCompressedFile(const QString &source) { QString suffix = QFileInfo(source).suffix(); - if (suffix == QStringLiteral("pkm")) + if (suffix == QLatin1String("pkm")) return setPkmFile(source); - else if (suffix == QStringLiteral("dds")) + else if (suffix == QLatin1String("dds")) return setDdsFile(source); else return false; |