diff options
| author | Joerg Bornemann <joerg.bornemann@digia.com> | 2013-03-25 18:23:05 +0100 |
|---|---|---|
| committer | Christian Kandeler <christian.kandeler@digia.com> | 2013-03-27 10:19:13 +0100 |
| commit | fabbefc70fe6308436cf6b4e32ba8c7b0d62da6e (patch) | |
| tree | 085403f27877864b99f0671dcaa97a02886eff32 /src/lib/buildgraph/transformer.cpp | |
| parent | 8561a8e88522453a3eced071d2ccf9b7e89d98d0 (diff) | |
| download | qbs-fabbefc70fe6308436cf6b4e32ba8c7b0d62da6e.tar.gz | |
cache Rule.prepare scripts as function objects
For Rule.prepare a function object is created on demand. This function
object is called on every rule application. The QScriptProgram cache
turns out to be quite useless.
This caching approach saves roughly 5% of time of the whole resolve
phase.
Magic persistence number changed, because the createCommands
method now expects prepare scripts in function form.
Change-Id: Ie531dcfb5f21578548a5961ddaa6086ae441a2b0
Reviewed-by: Christian Kandeler <christian.kandeler@digia.com>
Diffstat (limited to 'src/lib/buildgraph/transformer.cpp')
| -rw-r--r-- | src/lib/buildgraph/transformer.cpp | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/src/lib/buildgraph/transformer.cpp b/src/lib/buildgraph/transformer.cpp index f8f27d815..646b0330f 100644 --- a/src/lib/buildgraph/transformer.cpp +++ b/src/lib/buildgraph/transformer.cpp @@ -34,6 +34,7 @@ #include <jsextensions/moduleproperties.h> #include <language/language.h> #include <language/scriptengine.h> +#include <logging/translator.h> #include <tools/error.h> #include <tools/persistence.h> #include <tools/qbsassert.h> @@ -133,10 +134,15 @@ static AbstractCommand *createCommandFromScriptValue(const QScriptValue &scriptV void Transformer::createCommands(const PrepareScriptConstPtr &script, const RulesEvaluationContextPtr &evalContext) { - QScriptProgram scriptProgram = evalContext->scriptProgram(script->script); ScriptEngine * const engine = evalContext->engine(); + if (!script->scriptFunction.isValid() || script->scriptFunction.engine() != engine) { + script->scriptFunction = engine->evaluate(script->script); + if (!script->scriptFunction.isFunction()) + throw Error(Tr::tr("Invalid prepare script."), script->location); + } + engine->clearProperties(); - QScriptValue scriptValue = engine->evaluate(scriptProgram); + QScriptValue scriptValue = script->scriptFunction.call(); modulePropertiesUsedInPrepareScript = engine->properties(); if (engine->hasUncaughtException()) throw Error("evaluating prepare script: " + engine->uncaughtException().toString(), |
