aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib/corelib/tools/stringconstants.h
diff options
context:
space:
mode:
authorChristian Kandeler <christian.kandeler@qt.io>2017-11-16 17:50:24 +0100
committerChristian Kandeler <christian.kandeler@qt.io>2017-11-29 09:42:53 +0000
commitdd57e76a4322887e526999835ad0c61761b41674 (patch)
tree51bcfd302c9cc9316b5b7443d5b9ccb0c9733bd3 /src/lib/corelib/tools/stringconstants.h
parent75ac4e1c20f99013ea307ec134c3f9b5b150f8b4 (diff)
corelib: Gather string constants in central place
The same string literals appeared over and over again in the code base, causing redundancy in the sources as well as at run-time. We now give them a name and make sure they get instantiated at most once. String literals that occur only once are converted from QLatin1String to QStringLiteral unless they appear only in contexts that make use of QLatin1String overloads or they are clearly outside of any hot code paths. This seems to result in small, but measurable performance improvements, even if we assume the 1% changes to be noise: ========== Performance data for Resolving ========== Old instruction count: 3266514138 New instruction count: 3209355927 Relative change: -2 % Old peak memory usage: 29649896 Bytes New peak memory usage: 29436264 Bytes Relative change: -1 % ========== Performance data for Rule Execution ========== Old instruction count: 3367804753 New instruction count: 3319029596 Relative change: -2 % Old peak memory usage: 19577760 Bytes New peak memory usage: 19091328 Bytes Relative change: -3 % ========== Performance data for Null Build ========== Old instruction count: 608946535 New instruction count: 604566001 Relative change: -1 % Old peak memory usage: 14606384 Bytes New peak memory usage: 14579936 Bytes Relative change: -1 % Change-Id: Ia055a52e0a4b6fe6fd0f1e7ba4bfa583cba1b0ef Reviewed-by: Jake Petroules <jake.petroules@qt.io>
Diffstat (limited to 'src/lib/corelib/tools/stringconstants.h')
-rw-r--r--src/lib/corelib/tools/stringconstants.h229
1 files changed, 229 insertions, 0 deletions
diff --git a/src/lib/corelib/tools/stringconstants.h b/src/lib/corelib/tools/stringconstants.h
new file mode 100644
index 000000000..d4dc975ee
--- /dev/null
+++ b/src/lib/corelib/tools/stringconstants.h
@@ -0,0 +1,229 @@
+/****************************************************************************
+**
+** Copyright (C) 2017 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of Qbs.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QBS_STRINGCONSTANTS_H
+#define QBS_STRINGCONSTANTS_H
+
+#include <QtCore/qstringlist.h>
+
+#define QBS_CONSTANT(type, name, value) \
+ static const type &name() { \
+ static const type var{QLatin1String(value)}; \
+ return var; \
+ }
+#define QBS_STRING_CONSTANT(name, value) QBS_CONSTANT(QString, name, value)
+#define QBS_STRINGLIST_CONSTANT(name, value) QBS_CONSTANT(QStringList, name, value)
+
+namespace qbs {
+namespace Internal {
+
+class StringConstants
+{
+public:
+ static const QString &cppModule() { return cpp(); }
+ static const QString &qbsModule() { return qbs(); }
+
+ QBS_STRING_CONSTANT(aggregateProperty, "aggregate")
+ QBS_STRING_CONSTANT(additionalProductTypesProperty, "additionalProductTypes")
+ QBS_STRING_CONSTANT(allowedValuesProperty, "allowedValues")
+ QBS_STRING_CONSTANT(alwaysUpdatedProperty, "alwaysUpdated")
+ QBS_STRING_CONSTANT(alwaysRunProperty, "alwaysRun")
+ QBS_STRING_CONSTANT(auxiliaryInputsProperty, "auxiliaryInputs")
+ QBS_STRING_CONSTANT(baseNameProperty, "baseName")
+ QBS_STRING_CONSTANT(baseProfileProperty, "baseProfile")
+ QBS_STRING_CONSTANT(buildDirectoryProperty, "buildDirectory")
+ QBS_STRING_CONSTANT(builtByDefaultProperty, "builtByDefault")
+ QBS_STRING_CONSTANT(classNameProperty, "className")
+ QBS_STRING_CONSTANT(completeBaseNameProperty, "completeBaseName")
+ QBS_STRING_CONSTANT(conditionProperty, "condition")
+ QBS_STRING_CONSTANT(configurationNameProperty, "configurationName")
+ QBS_STRING_CONSTANT(configureProperty, "configure")
+ QBS_STRING_CONSTANT(consoleApplicationProperty, "consoleApplication")
+ QBS_STRING_CONSTANT(descriptionProperty, "description")
+ QBS_STRING_CONSTANT(destinationDirProperty, "destinationDirectory")
+ QBS_STRING_CONSTANT(excludeFilesProperty, "excludeFiles")
+ QBS_STRING_CONSTANT(excludedAuxiliaryInputsProperty, "excludedAuxiliaryInputs")
+ static const QString &explicitlyDependsOnProperty() { return explicitlyDependsOn(); }
+ static const QString &fileNameProperty() { return fileName(); }
+ static const QString &filePathProperty() { return filePath(); }
+ QBS_STRING_CONSTANT(fileTagsFilterProperty, "fileTagsFilter")
+ QBS_STRING_CONSTANT(fileTagsProperty, "fileTags")
+ QBS_STRING_CONSTANT(filesProperty, "files")
+ QBS_STRING_CONSTANT(filesAreTargetsProperty, "filesAreTargets")
+ QBS_STRING_CONSTANT(foundProperty, "found")
+ QBS_STRING_CONSTANT(inheritPropertiesProperty, "inheritProperties")
+ static const QString &inputsProperty() { return inputs(); }
+ QBS_STRING_CONSTANT(inputsFromDependenciesProperty, "inputsFromDependencies")
+ static const QString &installProperty() { return install(); }
+ QBS_STRING_CONSTANT(installRootProperty, "installRoot")
+ QBS_STRING_CONSTANT(installPrefixProperty, "installPrefix")
+ QBS_STRING_CONSTANT(installDirProperty, "installDir")
+ QBS_STRING_CONSTANT(installSourceBaseProperty, "installSourceBase")
+ QBS_STRING_CONSTANT(lengthProperty, "length")
+ QBS_STRING_CONSTANT(limitToSubProjectProperty, "limitToSubProject")
+ QBS_STRING_CONSTANT(minimumQbsVersionProperty, "minimumQbsVersion")
+ QBS_STRING_CONSTANT(moduleNameProperty, "moduleName")
+ QBS_STRING_CONSTANT(multiplexByQbsPropertiesProperty, "multiplexByQbsProperties")
+ QBS_STRING_CONSTANT(multiplexConfigurationIdProperty, "multiplexConfigurationId")
+ QBS_STRING_CONSTANT(multiplexConfigurationIdsProperty, "multiplexConfigurationIds")
+ QBS_STRING_CONSTANT(multiplexProperty, "multiplex")
+ QBS_STRING_CONSTANT(multiplexedProperty, "multiplexed")
+ QBS_STRING_CONSTANT(multiplexedTypeProperty, "multiplexedType")
+ QBS_STRING_CONSTANT(nameProperty, "name")
+ QBS_STRING_CONSTANT(outputArtifactsProperty, "outputArtifacts")
+ QBS_STRING_CONSTANT(outputFileTagsProperty, "outputFileTags")
+ QBS_STRING_CONSTANT(overrideTagsProperty, "overrideTags")
+ QBS_STRING_CONSTANT(overrideListPropertiesProperty, "overrideListProperties")
+ static const QString &pathProperty() { return path(); }
+ QBS_STRING_CONSTANT(patternsProperty, "patterns")
+ QBS_STRING_CONSTANT(prefixProperty, "prefix")
+ QBS_STRING_CONSTANT(prepareProperty, "prepare")
+ QBS_STRING_CONSTANT(presentProperty, "present")
+ QBS_STRING_CONSTANT(priorityProperty, "priority")
+ QBS_STRING_CONSTANT(profileProperty, "profile")
+ static const QString &profilesProperty() { return profiles(); }
+ QBS_STRING_CONSTANT(productTypesProperty, "productTypes")
+ QBS_STRING_CONSTANT(qbsSearchPathsProperty, "qbsSearchPaths")
+ QBS_STRING_CONSTANT(referencesProperty, "references")
+ QBS_STRING_CONSTANT(recursiveProperty, "recursive")
+ QBS_STRING_CONSTANT(requiredProperty, "required")
+ QBS_STRING_CONSTANT(requiresInputsProperty, "requiresInputs")
+ QBS_STRING_CONSTANT(removalVersionProperty, "removalVersion")
+ QBS_STRING_CONSTANT(scanProperty, "scan")
+ QBS_STRING_CONSTANT(searchPathsProperty, "searchPaths")
+ QBS_STRING_CONSTANT(setupBuildEnvironmentProperty, "setupBuildEnvironment")
+ QBS_STRING_CONSTANT(setupRunEnvironmentProperty, "setupRunEnvironment")
+ QBS_STRING_CONSTANT(sourceDirectoryProperty, "sourceDirectory")
+ QBS_STRING_CONSTANT(submodulesProperty, "submodules")
+ QBS_STRING_CONSTANT(targetNameProperty, "targetName")
+ QBS_STRING_CONSTANT(typeProperty, "type")
+ QBS_STRING_CONSTANT(validateProperty, "validate")
+ QBS_STRING_CONSTANT(versionProperty, "version")
+ QBS_STRING_CONSTANT(versionAtLeastProperty, "versionAtLeast")
+ QBS_STRING_CONSTANT(versionBelowProperty, "versionBelow")
+
+ QBS_STRING_CONSTANT(importScopeNamePropertyInternal, "_qbs_importScopeName")
+ QBS_STRING_CONSTANT(modulePropertyInternal, "__module")
+ QBS_STRING_CONSTANT(qbsSourceDirPropertyInternal, "_qbs_sourceDir")
+
+ static const QString &projectPrefix() { return project(); }
+ static const QString &productValue() { return product(); }
+
+ QBS_STRING_CONSTANT(baseVar, "base")
+ static const QString &explicitlyDependsOnVar() { return explicitlyDependsOn(); }
+ QBS_STRING_CONSTANT(inputVar, "input")
+ static const QString &inputsVar() { return inputs(); }
+ QBS_STRING_CONSTANT(originalVar, "original")
+ QBS_STRING_CONSTANT(outerVar, "outer")
+ QBS_STRING_CONSTANT(outputVar, "output")
+ QBS_STRING_CONSTANT(outputsVar, "outputs")
+ static const QString &productVar() { return product(); }
+ static const QString &projectVar() { return project(); }
+
+ static const QString &filePathGlobalVar() { return filePath(); }
+ static const QString &pathGlobalVar() { return path(); }
+
+ static const QString &pathType() { return path(); }
+
+ static const QString &fileInfoFileName() { return fileName(); }
+ static const QString &fileInfoPath() { return path(); }
+
+ static const QString &androidInstallCommand() { return install(); }
+ static const QString &simctlInstallCommand() { return install(); }
+
+ static const QString &profilesSettingsKey() { return profiles(); }
+
+ QBS_STRING_CONSTANT(emptyArrayValue, "[]")
+ QBS_STRING_CONSTANT(falseValue, "false")
+ QBS_STRING_CONSTANT(trueValue, "true")
+ QBS_STRING_CONSTANT(undefinedValue, "undefined")
+
+ QBS_STRING_CONSTANT(javaScriptCommandType, "JavaScriptCommand")
+ QBS_STRING_CONSTANT(commandType, "Command")
+
+ QBS_STRING_CONSTANT(pathEnvVar, "PATH")
+
+ QBS_STRING_CONSTANT(dot, ".")
+ QBS_STRING_CONSTANT(dotDot, "..")
+ QBS_STRING_CONSTANT(slashDotDot, "/..")
+ QBS_STRING_CONSTANT(star, "*")
+ QBS_STRING_CONSTANT(tildeSlash, "~/")
+
+ QBS_STRINGLIST_CONSTANT(qbsFileWildcards, "*.qbs")
+ QBS_STRINGLIST_CONSTANT(jsFileWildcards, "*.js")
+
+ static const QString &cppLang() { return cpp(); }
+
+ QBS_STRING_CONSTANT(xcode, "xcode")
+
+ QBS_STRING_CONSTANT(aarch64Arch, "aarch64")
+ QBS_STRING_CONSTANT(amd64Arch, "amd64")
+ QBS_STRING_CONSTANT(armArch, "arm")
+ QBS_STRING_CONSTANT(arm64Arch, "arm64")
+ QBS_STRING_CONSTANT(armv7Arch, "armv7")
+ QBS_STRING_CONSTANT(i386Arch, "i386")
+ QBS_STRING_CONSTANT(i586Arch, "i586")
+ QBS_STRING_CONSTANT(mipsArch, "mips")
+ QBS_STRING_CONSTANT(mips64Arch, "mips64")
+ QBS_STRING_CONSTANT(powerPcArch, "powerpc")
+ QBS_STRING_CONSTANT(ppcArch, "ppc")
+ QBS_STRING_CONSTANT(ppc64Arch, "ppc64")
+ QBS_STRING_CONSTANT(x86Arch, "x86")
+ QBS_STRING_CONSTANT(x86_64Arch, "x86_64")
+
+ QBS_STRING_CONSTANT(profilesSettingsPrefix, "profiles.")
+
+private:
+ QBS_STRING_CONSTANT(cpp, "cpp")
+ QBS_STRING_CONSTANT(explicitlyDependsOn, "explicitlyDependsOn")
+ QBS_STRING_CONSTANT(fileName, "fileName")
+ QBS_STRING_CONSTANT(filePath, "filePath")
+ QBS_STRING_CONSTANT(inputs, "inputs")
+ QBS_STRING_CONSTANT(install, "install")
+ QBS_STRING_CONSTANT(path, "path")
+ QBS_STRING_CONSTANT(product, "product")
+ QBS_STRING_CONSTANT(profiles, "profiles")
+ QBS_STRING_CONSTANT(project, "project")
+ QBS_STRING_CONSTANT(qbs, "qbs")
+};
+
+} // namespace Internal
+} // namespace qbs
+
+#endif // iInclude guard