diff options
author | Aaron Kennedy <aaron.kennedy@nokia.com> | 2009-09-28 11:21:25 (GMT) |
---|---|---|
committer | Aaron Kennedy <aaron.kennedy@nokia.com> | 2009-10-05 02:39:01 (GMT) |
commit | 061c85a17ecb303676b548e6daef6e64967ca1e7 (patch) | |
tree | 76cc1c8b2d33c0040794f1c161e95b4694e1bbad /src/declarative/qml/qmlexpression.cpp | |
parent | f9f878ca1fff08b6ea24507a84adfeb16d8938b6 (diff) | |
download | Qt-061c85a17ecb303676b548e6daef6e64967ca1e7.zip Qt-061c85a17ecb303676b548e6daef6e64967ca1e7.tar.gz Qt-061c85a17ecb303676b548e6daef6e64967ca1e7.tar.bz2 |
Use QScriptProgram to speed up binding creation
Diffstat (limited to 'src/declarative/qml/qmlexpression.cpp')
-rw-r--r-- | src/declarative/qml/qmlexpression.cpp | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/src/declarative/qml/qmlexpression.cpp b/src/declarative/qml/qmlexpression.cpp index db9d39f..adf5261 100644 --- a/src/declarative/qml/qmlexpression.cpp +++ b/src/declarative/qml/qmlexpression.cpp @@ -45,6 +45,7 @@ #include "qmlcontext_p.h" #include "qmlrewrite_p.h" #include "QtCore/qdebug.h" +#include "qmlcompiler_p.h" Q_DECLARE_METATYPE(QList<QObject *>); @@ -74,8 +75,26 @@ void QmlExpressionPrivate::init(QmlContext *ctxt, void *expr, QmlRefCount *rc, if (*data == BasicScriptEngineData) { sse.load((const char *)(data + 1), rc); } else { - expression = QString::fromRawData((QChar *)(data + 2), data[1]); + QmlCompiledData *dd = (QmlCompiledData *)rc; + expressionRewritten = true; + expression = QString::fromRawData((QChar *)(data + 3), data[2]); + + int progIdx = *(data + 1); + QmlEngine *engine = ctxt->engine(); + QScriptEngine *scriptEngine = QmlEnginePrivate::getScriptEngine(engine); + if (!dd->programs.at(progIdx)) { + dd->programs[progIdx] = new QScriptProgram(scriptEngine->compile(expression)); + } + + QmlContextPrivate *ctxtPriv = ctxt->d_func(); + QScriptContext *scriptContext = scriptEngine->pushContext(); + for (int i = ctxtPriv->scopeChain.size() - 1; i > -1; --i) + scriptContext->pushScope(ctxtPriv->scopeChain.at(i)); + + expressionFunction = scriptEngine->evaluate(*dd->programs[progIdx]); + expressionFunctionValid = true; + scriptEngine->popContext(); } QmlAbstractExpression::setContext(ctxt); |