summaryrefslogtreecommitdiffstats
path: root/src/declarative/qml/qmlcompiler.cpp
diff options
context:
space:
mode:
authorAaron Kennedy <aaron.kennedy@nokia.com>2009-08-05 04:15:10 (GMT)
committerAaron Kennedy <aaron.kennedy@nokia.com>2009-08-05 04:23:22 (GMT)
commit3c85728f2cb69817d4b72d3aab16b7a7fe6bdbf0 (patch)
tree01e245219495204a92b395797dafa1686347a27b /src/declarative/qml/qmlcompiler.cpp
parent2995f6eee6f718487c5f982c23cc6a4318fc58bb (diff)
downloadQt-3c85728f2cb69817d4b72d3aab16b7a7fe6bdbf0.zip
Qt-3c85728f2cb69817d4b72d3aab16b7a7fe6bdbf0.tar.gz
Qt-3c85728f2cb69817d4b72d3aab16b7a7fe6bdbf0.tar.bz2
Rewrite bindings inside the compiler
To improve execution performance, binding expressions are rewritten as function closures inside QmlExpression. To improve startup performance, where possible, the expressions are rewritten inside the compiler instead of inside QmlExpression at runtime. This also has the sideeffect of removing the StoreBinding instruction, as all bindings are now "compiled". The QmlBinding::expression() method for rewritten bindings will now return the rewritten expression instead of the original (which is lost), but this API is internal anyway.
Diffstat (limited to 'src/declarative/qml/qmlcompiler.cpp')
-rw-r--r--src/declarative/qml/qmlcompiler.cpp43
1 files changed, 28 insertions, 15 deletions
diff --git a/src/declarative/qml/qmlcompiler.cpp b/src/declarative/qml/qmlcompiler.cpp
index 197bd44..6ef7cc2 100644
--- a/src/declarative/qml/qmlcompiler.cpp
+++ b/src/declarative/qml/qmlcompiler.cpp
@@ -64,7 +64,9 @@
#include <private/qmlcomponent_p.h>
#include "parser/qmljsast_p.h"
#include <private/qmlvmemetaobject_p.h>
+#include <private/qmlexpression_p.h>
#include "qmlmetaproperty_p.h"
+#include "qmlrewrite_p.h"
#include "qmlscriptparser_p.h"
@@ -2062,14 +2064,11 @@ void QmlCompiler::genBindingAssignment(QmlParser::Value *binding,
const BindingReference &ref = compileState.bindings.value(binding);
QmlInstruction store;
- int dataRef;
- if (ref.compiledData.isEmpty()) {
- dataRef = output->indexForString(ref.expression.asScript());
- store.type = QmlInstruction::StoreBinding;
- } else {
- dataRef = output->indexForByteArray(ref.compiledData);
- store.type = QmlInstruction::StoreCompiledBinding;
- }
+ store.type = QmlInstruction::StoreCompiledBinding;
+ store.assignBinding.value = output->indexForByteArray(ref.compiledData);
+ store.assignBinding.context = ref.bindingContext.stack;
+ store.assignBinding.owner = ref.bindingContext.owner;
+ store.line = prop->location.end.line;
Q_ASSERT(ref.bindingContext.owner == 0 ||
(ref.bindingContext.owner != 0 && valueTypeProperty));
@@ -2081,18 +2080,12 @@ void QmlCompiler::genBindingAssignment(QmlParser::Value *binding,
store.assignBinding.property =
QmlMetaPropertyPrivate::saveProperty(prop->index);
}
- store.assignBinding.value = dataRef;
- store.assignBinding.context = ref.bindingContext.stack;
- store.assignBinding.owner = ref.bindingContext.owner;
- store.line = prop->location.end.line;
output->bytecode << store;
}
bool QmlCompiler::completeComponentBuild()
{
- saveComponentState();
-
for (int ii = 0; ii < compileState.aliasingObjects.count(); ++ii) {
Object *aliasObject = compileState.aliasingObjects.at(ii);
COMPILE_CHECK(buildDynamicMeta(aliasObject, ResolveAliases));
@@ -2111,11 +2104,31 @@ bool QmlCompiler::completeComponentBuild()
expr.expression = binding.expression;
bs.compile(expr);
- if (bs.isValid())
+ quint32 type;
+ if (bs.isValid()) {
binding.compiledData =
QByteArray(bs.compileData(), bs.compileDataSize());
+ type = QmlExpressionPrivate::BasicScriptEngineData;
+ } else {
+ type = QmlExpressionPrivate::PreTransformedQtScriptData;
+
+ // Pre-rewrite the expression
+ QString expression = binding.expression.asScript();
+ QmlRewrite::RewriteBinding rewriteBinding;
+ expression = rewriteBinding(expression);
+
+ quint32 length = expression.length();
+ binding.compiledData =
+ QByteArray((const char *)&length, sizeof(quint32)) +
+ QByteArray((const char *)expression.constData(),
+ expression.length() * sizeof(QChar));
+ }
+ binding.compiledData.prepend(QByteArray((const char *)&type,
+ sizeof(quint32)));
}
+ saveComponentState();
+
return true;
}