diff options
author | Aaron Kennedy <aaron.kennedy@nokia.com> | 2009-12-02 02:35:38 (GMT) |
---|---|---|
committer | Aaron Kennedy <aaron.kennedy@nokia.com> | 2009-12-02 02:35:38 (GMT) |
commit | cb70f2096cbc66e6e8b5324e0e9508c788144e7e (patch) | |
tree | dd4f6f98e2b27d09f2b7c275e705b5a28e89d541 /src/declarative/qml/qmlexpression.cpp | |
parent | ec42d6843ca0937f338e5e2d7d3353134d143eb6 (diff) | |
download | Qt-cb70f2096cbc66e6e8b5324e0e9508c788144e7e.zip Qt-cb70f2096cbc66e6e8b5324e0e9508c788144e7e.tar.gz Qt-cb70f2096cbc66e6e8b5324e0e9508c788144e7e.tar.bz2 |
Cache binding closures
Diffstat (limited to 'src/declarative/qml/qmlexpression.cpp')
-rw-r--r-- | src/declarative/qml/qmlexpression.cpp | 56 |
1 files changed, 45 insertions, 11 deletions
diff --git a/src/declarative/qml/qmlexpression.cpp b/src/declarative/qml/qmlexpression.cpp index d2d60ee..703fcf5 100644 --- a/src/declarative/qml/qmlexpression.cpp +++ b/src/declarative/qml/qmlexpression.cpp @@ -55,7 +55,7 @@ QT_BEGIN_NAMESPACE QmlExpressionData::QmlExpressionData() : expressionFunctionValid(false), expressionRewritten(false), me(0), - trackChange(true), line(-1), guardList(0), guardListLength(0) + trackChange(true), isShared(false), line(-1), guardList(0), guardListLength(0) { } @@ -108,27 +108,47 @@ void QmlExpressionPrivate::init(QmlContext *ctxt, void *expr, QmlRefCount *rc, data->expression = QString::fromRawData((QChar *)(exprData + 3), exprData[2]); int progIdx = *(exprData + 1); + bool isShared = progIdx & 0x80000000; + progIdx &= 0x7FFFFFFF; + QmlEngine *engine = ctxt->engine(); QmlEnginePrivate *ep = QmlEnginePrivate::get(engine); QScriptEngine *scriptEngine = QmlEnginePrivate::getScriptEngine(engine); + + if (isShared) { + + if (!dd->cachedValues.at(progIdx)) { + QScriptContext *scriptContext = QScriptDeclarativeClass::pushCleanContext(scriptEngine); + scriptContext->pushScope(ep->contextClass->newSharedContext()); + dd->cachedValues[progIdx] = new QScriptValue(scriptEngine->evaluate(data->expression, data->url.toString(), data->line)); + scriptEngine->popContext(); + } + + data->expressionFunction = *dd->cachedValues.at(progIdx); + data->isShared = true; + data->expressionFunctionValid = true; + + } else { + #if !defined(Q_OS_SYMBIAN) //XXX Why doesn't this work? - if (!dd->programs.at(progIdx)) { - dd->programs[progIdx] = - new QScriptProgram(data->expression, data->url.toString(), data->line); - } + if (!dd->programs.at(progIdx)) { + dd->programs[progIdx] = + new QScriptProgram(data->expression, data->url.toString(), data->line); + } #endif - QScriptContext *scriptContext = QScriptDeclarativeClass::pushCleanContext(scriptEngine); - scriptContext->pushScope(ep->contextClass->newContext(ctxt, me)); + QScriptContext *scriptContext = QScriptDeclarativeClass::pushCleanContext(scriptEngine); + scriptContext->pushScope(ep->contextClass->newContext(ctxt, me)); #if !defined(Q_OS_SYMBIAN) - data->expressionFunction = scriptEngine->evaluate(*dd->programs[progIdx]); + data->expressionFunction = scriptEngine->evaluate(*dd->programs[progIdx]); #else - data->expressionFunction = scriptEngine->evaluate(data->expression); + data->expressionFunction = scriptEngine->evaluate(data->expression); #endif - data->expressionFunctionValid = true; - scriptEngine->popContext(); + data->expressionFunctionValid = true; + scriptEngine->popContext(); + } } data->QmlAbstractExpression::setContext(ctxt); @@ -328,8 +348,22 @@ QVariant QmlExpressionPrivate::evalQtScript(QObject *secondaryScope, bool *isUnd data->expressionFunctionValid = true; } + QmlContext *oldSharedContext = 0; + QObject *oldSharedScope = 0; + if (data->isShared) { + oldSharedContext = ep->sharedContext; + oldSharedScope = ep->sharedScope; + ep->sharedContext = data->context(); + ep->sharedScope = data->me; + } + QScriptValue svalue = data->expressionFunction.call(); + if (data->isShared) { + ep->sharedContext = oldSharedContext; + ep->sharedScope = oldSharedScope; + } + if (isUndefined) *isUndefined = svalue.isUndefined() || scriptEngine->hasUncaughtException(); |