aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib/corelib/buildgraph/environmentscriptrunner.cpp
diff options
context:
space:
mode:
authorChristian Kandeler <christian.kandeler@qt.io>2017-11-20 16:00:03 +0100
committerChristian Kandeler <christian.kandeler@qt.io>2017-11-23 10:31:32 +0000
commit846b4ece2a8dcb6b407edbf9d0b23095e15f4566 (patch)
tree8409603af9a27243d388729b8e3b3014a9481b28 /src/lib/corelib/buildgraph/environmentscriptrunner.cpp
parente9b79f0d5165dc71dac10ed76b5fa06508672605 (diff)
Share ScriptFunction objects between products
The source code of script functions does not differ among module instantiations, so there's no need to give each product its own copy. For example, resolving the QtCreator super project now allocates about 80 of these objects, rather than 16000, each of which had their own unshared copy of the script source code. Change-Id: I10d67991ce170826346d434fe58ea6608fa18a1f 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.cpp24
1 files changed, 13 insertions, 11 deletions
diff --git a/src/lib/corelib/buildgraph/environmentscriptrunner.cpp b/src/lib/corelib/buildgraph/environmentscriptrunner.cpp
index 6a143c16f..ef9fe7aff 100644
--- a/src/lib/corelib/buildgraph/environmentscriptrunner.cpp
+++ b/src/lib/corelib/buildgraph/environmentscriptrunner.cpp
@@ -124,7 +124,7 @@ void EnvironmentScriptRunner::setupForRun(const QStringList &config)
void EnvironmentScriptRunner::setupEnvironment()
{
const auto hasScript = [this](const ResolvedModuleConstPtr &m) {
- return !getScript(m.get())->sourceCode.isEmpty();
+ return !getScript(m.get()).sourceCode().isEmpty();
};
const bool hasAnyScripts = std::any_of(m_product->modules.cbegin(), m_product->modules.cend(),
hasScript);
@@ -163,8 +163,8 @@ void EnvironmentScriptRunner::setupEnvironment()
? ResolvedModule::argumentNamesForSetupBuildEnv()
: ResolvedModule::argumentNamesForSetupRunEnv();
for (const ResolvedModule * const module : topSortedModules) {
- const ScriptFunction *setupScript = getScript(module);
- if (setupScript->sourceCode.isEmpty())
+ const PrivateScriptFunction &setupScript = getScript(module);
+ if (setupScript.sourceCode().isEmpty())
continue;
RulesEvaluationContext::Scope s(m_evalContext);
@@ -181,11 +181,12 @@ void EnvironmentScriptRunner::setupEnvironment()
configArray.setProperty(i, QScriptValue(m_runEnvConfig.at(i)));
m_evalContext->scope().setProperty(QLatin1String("config"), configArray);
}
- setupScriptEngineForFile(engine(), setupScript->fileContext, m_evalContext->scope(),
+ setupScriptEngineForFile(engine(), setupScript.fileContext(), m_evalContext->scope(),
ObserveMode::Disabled);
- QScriptValue fun = engine()->evaluate(setupScript->sourceCode,
- setupScript->location.filePath(),
- setupScript->location.line());
+ // TODO: Cache evaluate result
+ QScriptValue fun = engine()->evaluate(setupScript.sourceCode(),
+ setupScript.location().filePath(),
+ setupScript.location().line());
QBS_CHECK(fun.isFunction());
const QScriptValueList svArgs = ScriptEngine::argumentList(scriptFunctionArgs,
m_evalContext->scope());
@@ -197,7 +198,7 @@ void EnvironmentScriptRunner::setupEnvironment()
throw ErrorInfo(Tr::tr("Error running %1 script for product '%2': %3")
.arg(scriptName, m_product->fullDisplayName(),
engine()->lastErrorString(res)),
- engine()->lastErrorLocation(res, setupScript->location));
+ engine()->lastErrorLocation(res, setupScript.location()));
}
}
@@ -213,10 +214,11 @@ ScriptEngine *EnvironmentScriptRunner::engine() const
return m_evalContext->engine();
}
-const ScriptFunction *EnvironmentScriptRunner::getScript(const ResolvedModule *module) const
+const PrivateScriptFunction &EnvironmentScriptRunner::getScript(const ResolvedModule *module) const
{
- return (m_envType == BuildEnv
- ? module->setupBuildEnvironmentScript : module->setupRunEnvironmentScript).get();
+ return m_envType == BuildEnv
+ ? module->setupBuildEnvironmentScript
+ : module->setupRunEnvironmentScript;
}
} // namespace Internal