diff options
author | Aaron Kennedy <aaron.kennedy@nokia.com> | 2009-08-05 04:15:10 (GMT) |
---|---|---|
committer | Aaron Kennedy <aaron.kennedy@nokia.com> | 2009-08-05 04:23:22 (GMT) |
commit | 3c85728f2cb69817d4b72d3aab16b7a7fe6bdbf0 (patch) | |
tree | 01e245219495204a92b395797dafa1686347a27b /src/declarative/qml/qmlexpression.cpp | |
parent | 2995f6eee6f718487c5f982c23cc6a4318fc58bb (diff) | |
download | Qt-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/qmlexpression.cpp')
-rw-r--r-- | src/declarative/qml/qmlexpression.cpp | 24 |
1 files changed, 19 insertions, 5 deletions
diff --git a/src/declarative/qml/qmlexpression.cpp b/src/declarative/qml/qmlexpression.cpp index 2c06efa..148ff71 100644 --- a/src/declarative/qml/qmlexpression.cpp +++ b/src/declarative/qml/qmlexpression.cpp @@ -51,7 +51,7 @@ Q_DECLARE_METATYPE(QList<QObject *>); QT_BEGIN_NAMESPACE QmlExpressionPrivate::QmlExpressionPrivate() -: ctxt(0), expressionFunctionValid(false), sseData(0), me(0), trackChange(true), line(-1), guardList(0), guardListLength(0) +: ctxt(0), expressionFunctionValid(false), expressionRewritten(false), sseData(0), me(0), trackChange(true), line(-1), guardList(0), guardListLength(0) { } @@ -73,7 +73,15 @@ void QmlExpressionPrivate::init(QmlContext *ctxt, void *expr, QmlRefCount *rc, { Q_Q(QmlExpression); - sse.load((const char *)expr, rc); + quint32 *data = (quint32 *)expr; + Q_ASSERT(*data == BasicScriptEngineData || + *data == PreTransformedQtScriptData); + if (*data == BasicScriptEngineData) { + sse.load((const char *)(data + 1), rc); + } else { + expression = QString::fromRawData((QChar *)(data + 2), data[1]); + expressionRewritten = true; + } this->ctxt = ctxt; if (ctxt) @@ -203,6 +211,7 @@ void QmlExpression::setExpression(const QString &expression) d->expression = expression; d->expressionFunctionValid = false; + d->expressionRewritten = false; d->expressionFunction = QScriptValue(); d->sse.clear(); @@ -250,10 +259,15 @@ QVariant QmlExpressionPrivate::evalQtScript() scriptEngine->currentContext()->pushScope(ctxtPriv->scopeChain.at(i)); if (!expressionFunctionValid) { - QmlRewrite::RewriteBinding rewriteBinding; - const QString code = rewriteBinding(expression); - expressionFunction = scriptEngine->evaluate(code, fileName, line); + if (expressionRewritten) { + expressionFunction = scriptEngine->evaluate(expression, fileName, line); + } else { + QmlRewrite::RewriteBinding rewriteBinding; + + const QString code = rewriteBinding(expression); + expressionFunction = scriptEngine->evaluate(code, fileName, line); + } expressionFunctionValid = true; } |