diff options
author | Michael Brasser <michael.brasser@nokia.com> | 2010-12-15 02:08:13 (GMT) |
---|---|---|
committer | Michael Brasser <michael.brasser@nokia.com> | 2010-12-17 06:35:17 (GMT) |
commit | 488e616b50707e5b37162e6d0cfc71a1ffdf9bef (patch) | |
tree | 86b02b1665e7dcc29aed479c9ed2ce7d6f5ba214 /src/declarative/util/qdeclarativepropertychanges.cpp | |
parent | 139ecc0e74af2795faa55cfd532aeb10c631049e (diff) | |
download | Qt-488e616b50707e5b37162e6d0cfc71a1ffdf9bef.zip Qt-488e616b50707e5b37162e6d0cfc71a1ffdf9bef.tar.gz Qt-488e616b50707e5b37162e6d0cfc71a1ffdf9bef.tar.bz2 |
Rewrite/cache bindings created by PropertyChanges.
This provides a significant optimization for initial evaluation of
bindings specified in a PropertyChanges.
Reviewed-by: Aaron Kennedy
Diffstat (limited to 'src/declarative/util/qdeclarativepropertychanges.cpp')
-rw-r--r-- | src/declarative/util/qdeclarativepropertychanges.cpp | 26 |
1 files changed, 23 insertions, 3 deletions
diff --git a/src/declarative/util/qdeclarativepropertychanges.cpp b/src/declarative/util/qdeclarativepropertychanges.cpp index 8d01b80..400803e 100644 --- a/src/declarative/util/qdeclarativepropertychanges.cpp +++ b/src/declarative/util/qdeclarativepropertychanges.cpp @@ -42,6 +42,9 @@ #include "private/qdeclarativepropertychanges_p.h" #include "private/qdeclarativeopenmetaobject_p.h" +#include "private/qdeclarativerewrite_p.h" +#include "private/qdeclarativeengine_p.h" +#include "private/qdeclarativecompiler_p.h" #include <qdeclarativeinfo.h> #include <qdeclarativecustomparser_p.h> @@ -219,6 +222,7 @@ public: QList<QPair<QByteArray, QVariant> > properties; QList<QPair<QByteArray, QDeclarativeExpression *> > expressions; + QList<QDeclarativeBinding::Identifier> ids; QList<QDeclarativeReplaceSignalHandler*> signalReplacements; QDeclarativeProperty property(const QByteArray &); @@ -267,6 +271,7 @@ QDeclarativePropertyChangesParser::compile(const QList<QDeclarativeCustomParserP QDeclarativeParser::Variant v = qvariant_cast<QDeclarativeParser::Variant>(data.at(ii).second); QVariant var; bool isScript = v.isScript(); + QDeclarativeBinding::Identifier id; switch(v.type()) { case QDeclarativeParser::Variant::Boolean: var = QVariant(v.asBoolean()); @@ -280,10 +285,17 @@ QDeclarativePropertyChangesParser::compile(const QList<QDeclarativeCustomParserP case QDeclarativeParser::Variant::Invalid: case QDeclarativeParser::Variant::Script: var = QVariant(v.asScript()); + { + // Pre-rewrite the expression + QString expression = v.asScript(); + id = rewriteBinding(expression, data.at(ii).first); //### recreates the AST, which is slow + } break; } ds << data.at(ii).first << isScript << var; + if (isScript) + ds << id; } return rv; @@ -303,9 +315,12 @@ void QDeclarativePropertyChangesPrivate::decode() QByteArray name; bool isScript; QVariant data; + QDeclarativeBinding::Identifier id; ds >> name; ds >> isScript; ds >> data; + if (isScript) + ds >> id; QDeclarativeProperty prop = property(name); //### better way to check for signal property? if (prop.type() & QDeclarativeProperty::SignalProperty) { @@ -323,6 +338,7 @@ void QDeclarativePropertyChangesPrivate::decode() if (ddata && ddata->outerContext && !ddata->outerContext->url.isEmpty()) expression->setSourceLocation(ddata->outerContext->url.toString(), ddata->lineNumber); expressions << qMakePair(name, expression); + ids << id; } else { properties << qMakePair(name, data); } @@ -452,10 +468,14 @@ QDeclarativePropertyChanges::ActionList QDeclarativePropertyChanges::actions() a.toValue = d->expressions.at(ii).second->evaluate(); } else { QDeclarativeExpression *e = d->expressions.at(ii).second; - QDeclarativeBinding *newBinding = - new QDeclarativeBinding(e->expression(), object(), qmlContext(this)); + + QDeclarativeBinding::Identifier id = d->ids.at(ii); + QDeclarativeBinding *newBinding = QDeclarativeBinding::createBinding(id, object(), qmlContext(this), e->sourceFile(), e->lineNumber()); + if (!newBinding) { + newBinding = new QDeclarativeBinding(e->expression(), object(), qmlContext(this)); + newBinding->setSourceLocation(e->sourceFile(), e->lineNumber()); + } newBinding->setTarget(prop); - newBinding->setSourceLocation(e->sourceFile(), e->lineNumber()); a.toBinding = newBinding; a.deletableToBinding = true; } |