diff options
author | Aaron Kennedy <aaron.kennedy@nokia.com> | 2009-08-11 03:59:56 (GMT) |
---|---|---|
committer | Aaron Kennedy <aaron.kennedy@nokia.com> | 2009-08-11 03:59:56 (GMT) |
commit | a57bcdde329ef4c9a71aa6ba714f5e30ffd5dc6d (patch) | |
tree | 64cde5908b51e852a3c761031b809f3f056cec16 /src/declarative/qml/qmlcompiler.cpp | |
parent | 712b8ecad2407645ef80fef94181782d2227b002 (diff) | |
download | Qt-a57bcdde329ef4c9a71aa6ba714f5e30ffd5dc6d.zip Qt-a57bcdde329ef4c9a71aa6ba714f5e30ffd5dc6d.tar.gz Qt-a57bcdde329ef4c9a71aa6ba714f5e30ffd5dc6d.tar.bz2 |
Object property binding optimization
Add a binding optimization that hits
anchors.fill: parent
Diffstat (limited to 'src/declarative/qml/qmlcompiler.cpp')
-rw-r--r-- | src/declarative/qml/qmlcompiler.cpp | 40 |
1 files changed, 37 insertions, 3 deletions
diff --git a/src/declarative/qml/qmlcompiler.cpp b/src/declarative/qml/qmlcompiler.cpp index 7c0964b..75ed94b 100644 --- a/src/declarative/qml/qmlcompiler.cpp +++ b/src/declarative/qml/qmlcompiler.cpp @@ -2069,6 +2069,7 @@ void QmlCompiler::genBindingAssignment(QmlParser::Value *binding, QmlBasicScript bs; if (ref.isBasicScript) bs.load(ref.compiledData.constData() + sizeof(quint32)); + if (bs.isSingleIdFetch()) { int idIndex = bs.singleIdFetchIndex(); QmlParser::Object *idObj = compileState.idIndexes.value(idIndex); @@ -2079,9 +2080,26 @@ void QmlCompiler::genBindingAssignment(QmlParser::Value *binding, output->bytecode << store; return; } + } else if (bs.isSingleContextProperty()) { + int propIndex = bs.singleContextPropertyIndex(); + + QMetaProperty p = + ref.bindingContext.object->metaObject()->property(propIndex); + if ((p.notifySignalIndex() != -1 || p.isConstant()) && + canCoerce(prop->type, p.userType())) { + + store.type = QmlInstruction::StoreObjPropBinding; + store.assignObjPropBinding.property = prop->index; + store.assignObjPropBinding.contextIdx = propIndex; + store.assignObjPropBinding.context = ref.bindingContext.stack; + store.assignObjPropBinding.notifyIdx = p.notifySignalIndex(); + + output->bytecode << store; + return; + } } - store.type = QmlInstruction::StoreCompiledBinding; + store.type = QmlInstruction::StoreBinding; store.assignBinding.value = output->indexForByteArray(ref.compiledData); store.assignBinding.context = ref.bindingContext.stack; store.assignBinding.owner = ref.bindingContext.owner; @@ -2157,8 +2175,7 @@ bool QmlCompiler::completeComponentBuild() */ bool QmlCompiler::canCoerce(int to, QmlParser::Object *from) { - const QMetaObject *toMo = - QmlMetaType::rawMetaObjectForType(to); + const QMetaObject *toMo = QmlMetaType::rawMetaObjectForType(to); const QMetaObject *fromMo = from->metaObject(); while (fromMo) { @@ -2169,6 +2186,23 @@ bool QmlCompiler::canCoerce(int to, QmlParser::Object *from) return false; } +/*! + Returns true if from can be assigned to a (QObject) property of type + to. +*/ +bool QmlCompiler::canCoerce(int to, int from) +{ + const QMetaObject *toMo = QmlMetaType::rawMetaObjectForType(to); + const QMetaObject *fromMo = QmlMetaType::rawMetaObjectForType(from); + + while (fromMo) { + if (fromMo == toMo) + return true; + fromMo = fromMo->superClass(); + } + return false; +} + QmlType *QmlCompiler::toQmlType(QmlParser::Object *from) { // ### Optimize |