aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib/corelib/buildgraph/transformer.cpp
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/buildgraph/transformer.cpp
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/buildgraph/transformer.cpp')
-rw-r--r--src/lib/corelib/buildgraph/transformer.cpp34
1 files changed, 18 insertions, 16 deletions
diff --git a/src/lib/corelib/buildgraph/transformer.cpp b/src/lib/corelib/buildgraph/transformer.cpp
index 77bf1de0d..9c7178c17 100644
--- a/src/lib/corelib/buildgraph/transformer.cpp
+++ b/src/lib/corelib/buildgraph/transformer.cpp
@@ -49,6 +49,7 @@
#include <tools/persistence.h>
#include <tools/scripttools.h>
#include <tools/qbsassert.h>
+#include <tools/stringconstants.h>
#include <QtCore/qdir.h>
@@ -111,15 +112,16 @@ QScriptValue Transformer::translateFileConfig(ScriptEngine *scriptEngine, const
QScriptValue obj = scriptEngine->newObject();
attachPointerTo(obj, artifact);
ModuleProperties::init(obj, artifact);
- obj.setProperty(QLatin1String("fileName"), artifact->fileName());
- obj.setProperty(QLatin1String("filePath"), artifact->filePath());
- setArtifactProperty(obj, QLatin1String("baseName"), js_baseName, artifact);
- setArtifactProperty(obj, QLatin1String("completeBaseName"), js_completeBaseName, artifact);
- setArtifactProperty(obj, QLatin1String("baseDir"), js_baseDir, artifact);
+ obj.setProperty(StringConstants::fileNameProperty(), artifact->fileName());
+ obj.setProperty(StringConstants::filePathProperty(), artifact->filePath());
+ setArtifactProperty(obj, StringConstants::baseNameProperty(), js_baseName, artifact);
+ setArtifactProperty(obj, StringConstants::completeBaseNameProperty(), js_completeBaseName,
+ artifact);
+ setArtifactProperty(obj, QStringLiteral("baseDir"), js_baseDir, artifact);
const QStringList fileTags = artifact->fileTags().toStringList();
- obj.setProperty(QLatin1String("fileTags"), scriptEngine->toScriptValue(fileTags));
+ obj.setProperty(StringConstants::fileTagsProperty(), scriptEngine->toScriptValue(fileTags));
if (!defaultModuleName.isEmpty())
- obj.setProperty(QLatin1String("moduleName"), defaultModuleName);
+ obj.setProperty(StringConstants::moduleNameProperty(), defaultModuleName);
return obj;
}
@@ -167,7 +169,7 @@ void Transformer::setupInputs(QScriptValue targetScriptValue, const ArtifactSet
{
ScriptEngine *const scriptEngine = static_cast<ScriptEngine *>(targetScriptValue.engine());
QScriptValue scriptValue = translateInOutputs(scriptEngine, inputs, defaultModuleName);
- targetScriptValue.setProperty(QLatin1String("inputs"), scriptValue);
+ targetScriptValue.setProperty(StringConstants::inputsVar(), scriptValue);
QScriptValue inputScriptValue;
if (inputs.size() == 1) {
Artifact *input = *inputs.cbegin();
@@ -176,7 +178,7 @@ void Transformer::setupInputs(QScriptValue targetScriptValue, const ArtifactSet
QScriptValue inputsForFileTag = scriptValue.property(fileTags.cbegin()->toString());
inputScriptValue = inputsForFileTag.property(0);
}
- targetScriptValue.setProperty(QLatin1String("input"), inputScriptValue);
+ targetScriptValue.setProperty(StringConstants::inputVar(), inputScriptValue);
}
void Transformer::setupInputs(QScriptValue targetScriptValue)
@@ -189,7 +191,7 @@ void Transformer::setupOutputs(QScriptValue targetScriptValue)
ScriptEngine * const scriptEngine = static_cast<ScriptEngine *>(targetScriptValue.engine());
const QString &defaultModuleName = rule->module->name;
QScriptValue scriptValue = translateInOutputs(scriptEngine, outputs, defaultModuleName);
- targetScriptValue.setProperty(QLatin1String("outputs"), scriptValue);
+ targetScriptValue.setProperty(StringConstants::outputsVar(), scriptValue);
QScriptValue outputScriptValue;
if (outputs.size() == 1) {
Artifact *output = *outputs.cbegin();
@@ -198,7 +200,7 @@ void Transformer::setupOutputs(QScriptValue targetScriptValue)
QScriptValue outputsForFileTag = scriptValue.property(fileTags.cbegin()->toString());
outputScriptValue = outputsForFileTag.property(0);
}
- targetScriptValue.setProperty(QLatin1String("output"), outputScriptValue);
+ targetScriptValue.setProperty(StringConstants::outputVar(), outputScriptValue);
}
void Transformer::setupExplicitlyDependsOn(QScriptValue targetScriptValue)
@@ -206,7 +208,7 @@ void Transformer::setupExplicitlyDependsOn(QScriptValue targetScriptValue)
ScriptEngine * const scriptEngine = static_cast<ScriptEngine *>(targetScriptValue.engine());
QScriptValue scriptValue = translateInOutputs(scriptEngine, explicitlyDependsOn,
rule->module->name);
- targetScriptValue.setProperty(QLatin1String("explicitlyDependsOn"), scriptValue);
+ targetScriptValue.setProperty(StringConstants::explicitlyDependsOnVar(), scriptValue);
}
static AbstractCommandPtr createCommandFromScriptValue(const QScriptValue &scriptValue,
@@ -215,10 +217,10 @@ static AbstractCommandPtr createCommandFromScriptValue(const QScriptValue &scrip
AbstractCommandPtr cmdBase;
if (scriptValue.isUndefined() || !scriptValue.isValid())
return cmdBase;
- QString className = scriptValue.property(QLatin1String("className")).toString();
- if (className == QLatin1String("Command"))
+ QString className = scriptValue.property(StringConstants::classNameProperty()).toString();
+ if (className == StringConstants::commandType())
cmdBase = ProcessCommand::create();
- else if (className == QLatin1String("JavaScriptCommand"))
+ else if (className == StringConstants::javaScriptCommandType())
cmdBase = JavaScriptCommand::create();
if (cmdBase)
cmdBase->fillFromScriptValue(&scriptValue, codeLocation);
@@ -246,7 +248,7 @@ void Transformer::createCommands(ScriptEngine *engine, const PrivateScriptFuncti
throw engine->lastError(scriptValue, script.location());
commands.clear();
if (scriptValue.isArray()) {
- const int count = scriptValue.property(QLatin1String("length")).toInt32();
+ const int count = scriptValue.property(StringConstants::lengthProperty()).toInt32();
for (qint32 i = 0; i < count; ++i) {
QScriptValue item = scriptValue.property(i);
if (item.isValid() && !item.isUndefined()) {