aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib/corelib/buildgraph/environmentscriptrunner.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/environmentscriptrunner.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/environmentscriptrunner.cpp')
-rw-r--r--src/lib/corelib/buildgraph/environmentscriptrunner.cpp12
1 files changed, 7 insertions, 5 deletions
diff --git a/src/lib/corelib/buildgraph/environmentscriptrunner.cpp b/src/lib/corelib/buildgraph/environmentscriptrunner.cpp
index ef9fe7aff..a80687a2b 100644
--- a/src/lib/corelib/buildgraph/environmentscriptrunner.cpp
+++ b/src/lib/corelib/buildgraph/environmentscriptrunner.cpp
@@ -48,6 +48,7 @@
#include <tools/qbsassert.h>
#include <tools/qttools.h>
#include <logging/translator.h>
+#include <tools/stringconstants.h>
#include <QtCore/qhash.h>
#include <QtCore/qvariant.h>
@@ -171,15 +172,15 @@ void EnvironmentScriptRunner::setupEnvironment()
QScriptValue envScriptContext = engine()->newObject();
envScriptContext.setPrototype(engine()->globalObject());
setupScriptEngineForProduct(engine(), m_product, module, envScriptContext, nullptr, false);
- static const QString productKey = QStringLiteral("product");
- static const QString projectKey = QStringLiteral("project");
+ const QString &productKey = StringConstants::productVar();
+ const QString &projectKey = StringConstants::projectVar();
m_evalContext->scope().setProperty(productKey, envScriptContext.property(productKey));
m_evalContext->scope().setProperty(projectKey, envScriptContext.property(projectKey));
if (m_envType == RunEnv) {
QScriptValue configArray = engine()->newArray(m_runEnvConfig.size());
for (int i = 0; i < m_runEnvConfig.size(); ++i)
configArray.setProperty(i, QScriptValue(m_runEnvConfig.at(i)));
- m_evalContext->scope().setProperty(QLatin1String("config"), configArray);
+ m_evalContext->scope().setProperty(QStringLiteral("config"), configArray);
}
setupScriptEngineForFile(engine(), setupScript.fileContext(), m_evalContext->scope(),
ObserveMode::Disabled);
@@ -193,8 +194,9 @@ void EnvironmentScriptRunner::setupEnvironment()
const QScriptValue res = fun.call(QScriptValue(), svArgs);
engine()->releaseResourcesOfScriptObjects();
if (Q_UNLIKELY(engine()->hasErrorOrException(res))) {
- const QString scriptName = QLatin1String(m_envType == BuildEnv ? "setupBuildEnvironment"
- : "setupRunEnvironment");
+ const QString scriptName = m_envType == BuildEnv
+ ? StringConstants::setupBuildEnvironmentProperty()
+ : StringConstants::setupRunEnvironmentProperty();
throw ErrorInfo(Tr::tr("Error running %1 script for product '%2': %3")
.arg(scriptName, m_product->fullDisplayName(),
engine()->lastErrorString(res)),