diff options
author | Aaron Kennedy <aaron.kennedy@nokia.com> | 2010-03-25 07:49:33 (GMT) |
---|---|---|
committer | Aaron Kennedy <aaron.kennedy@nokia.com> | 2010-03-25 07:51:14 (GMT) |
commit | 72599ca45c416f2f0a9654412c14a148ca3d728c (patch) | |
tree | 9a48998382adf499e52d8a8a9b6169fbfa520374 /src | |
parent | 672e06aef096d3e7a81826b28121f3314948eeff (diff) | |
download | Qt-72599ca45c416f2f0a9654412c14a148ca3d728c.zip Qt-72599ca45c416f2f0a9654412c14a148ca3d728c.tar.gz Qt-72599ca45c416f2f0a9654412c14a148ca3d728c.tar.bz2 |
Optimize QML "parent" property access
For properties that are as important as "parent", QML cannot afford the
overhead of a signal/slot connection.
Diffstat (limited to 'src')
-rw-r--r-- | src/declarative/graphicsitems/qdeclarativeitem.cpp | 11 | ||||
-rw-r--r-- | src/declarative/graphicsitems/qdeclarativeitem_p.h | 6 | ||||
-rw-r--r-- | src/declarative/qml/qdeclarativecompiledbindings.cpp | 88 | ||||
-rw-r--r-- | src/declarative/qml/qml.pri | 2 |
4 files changed, 91 insertions, 16 deletions
diff --git a/src/declarative/graphicsitems/qdeclarativeitem.cpp b/src/declarative/graphicsitems/qdeclarativeitem.cpp index e6ade00..ee0682a 100644 --- a/src/declarative/graphicsitems/qdeclarativeitem.cpp +++ b/src/declarative/graphicsitems/qdeclarativeitem.cpp @@ -1554,6 +1554,14 @@ void QDeclarativeItemPrivate::transform_clear(QDeclarativeListProperty<QGraphics } } +void QDeclarativeItemPrivate::parentProperty(QObject *o, void *rv, QDeclarativeNotifierEndpoint *e) +{ + QDeclarativeItem *item = static_cast<QDeclarativeItem*>(o); + if (e) + e->connect(&item->d_func()->parentNotifier); + *((QDeclarativeItem **)rv) = item->parentItem(); +} + /*! \qmlproperty list<Object> Item::data \default @@ -2539,10 +2547,11 @@ bool QDeclarativeItem::sceneEvent(QEvent *event) QVariant QDeclarativeItem::itemChange(GraphicsItemChange change, const QVariant &value) { - Q_D(const QDeclarativeItem); + Q_D(QDeclarativeItem); switch (change) { case ItemParentHasChanged: emit parentChanged(parentItem()); + d->parentNotifier.notify(); break; case ItemChildAddedChange: case ItemChildRemovedChange: diff --git a/src/declarative/graphicsitems/qdeclarativeitem_p.h b/src/declarative/graphicsitems/qdeclarativeitem_p.h index 56b0d77..4828f4e 100644 --- a/src/declarative/graphicsitems/qdeclarativeitem_p.h +++ b/src/declarative/graphicsitems/qdeclarativeitem_p.h @@ -62,6 +62,8 @@ #include <private/qdeclarativestate_p.h> #include <private/qdeclarativenullablevalue_p_p.h> +#include <private/qdeclarativenotifier_p.h> + #include <qdeclarative.h> #include <qdeclarativecontext.h> @@ -160,6 +162,10 @@ public: static QGraphicsTransform *transform_at(QDeclarativeListProperty<QGraphicsTransform> *list, int); static void transform_clear(QDeclarativeListProperty<QGraphicsTransform> *list); + // Accelerated property accessors + QDeclarativeNotifier parentNotifier; + static void parentProperty(QObject *o, void *rv, QDeclarativeNotifierEndpoint *e); + QDeclarativeAnchors *anchors() { if (!_anchors) { Q_Q(QDeclarativeItem); diff --git a/src/declarative/qml/qdeclarativecompiledbindings.cpp b/src/declarative/qml/qdeclarativecompiledbindings.cpp index 1acca2f..67750a4 100644 --- a/src/declarative/qml/qdeclarativecompiledbindings.cpp +++ b/src/declarative/qml/qdeclarativecompiledbindings.cpp @@ -53,11 +53,15 @@ #include <QtCore/qnumeric.h> #include <private/qdeclarativeanchors_p_p.h> #include <private/qdeclarativeglobal_p.h> +#include <private/qdeclarativefastproperties_p.h> QT_BEGIN_NAMESPACE DEFINE_BOOL_CONFIG_OPTION(qmlExperimental, QML_EXPERIMENTAL); DEFINE_BOOL_CONFIG_OPTION(qmlDisableOptimizer, QML_DISABLE_OPTIMIZER); +DEFINE_BOOL_CONFIG_OPTION(qmlDisableFastProperties, QML_DISABLE_FAST_PROPERTIES); + +Q_GLOBAL_STATIC(QDeclarativeFastProperties, fastProperties); using namespace QDeclarativeJS; @@ -334,6 +338,8 @@ struct Instr { Subscribe, // subscribe SubscribeId, // subscribe + FetchAndSubscribe, // fetchAndSubscribe + LoadId, // load LoadScope, // load LoadRoot, // load @@ -433,6 +439,14 @@ struct Instr { qint8 output; qint8 objectReg; quint8 exceptionId; + quint16 subscription; + quint16 function; + } fetchAndSubscribe; + struct { + quint8 type; + qint8 output; + qint8 objectReg; + quint8 exceptionId; quint32 index; } fetch; struct { @@ -937,6 +951,9 @@ static void dumpInstruction(const Instr *instr) case Instr::SubscribeId: qWarning().nospace() << "SubscribeId" << "\t\t" << instr->subscribe.offset << "\t" << instr->subscribe.reg << "\t" << instr->subscribe.index; break; + case Instr::FetchAndSubscribe: + qWarning().nospace() << "FetchAndSubscribe" << "\t" << instr->fetchAndSubscribe.output << "\t" << instr->fetchAndSubscribe.objectReg << "\t" << instr->fetchAndSubscribe.subscription; + break; case Instr::LoadId: qWarning().nospace() << "LoadId" << "\t\t\t" << instr->load.index << "\t" << instr->load.reg; break; @@ -1070,6 +1087,8 @@ void QDeclarativeCompiledBindingsPrivate::run(int instrIndex, QDeclarativeContextData *context, QDeclarativeDelayedError *error, QObject *scope, QObject *output) { + Q_Q(QDeclarativeCompiledBindings); + error->removeError(); Register registers[32]; @@ -1081,6 +1100,7 @@ void QDeclarativeCompiledBindingsPrivate::run(int instrIndex, instr += instrIndex; const char *data = program->data(); + // return; #ifdef COMPILEDBINDINGS_DEBUG qWarning().nospace() << "Begin binding run"; #endif @@ -1107,6 +1127,32 @@ void QDeclarativeCompiledBindingsPrivate::run(int instrIndex, } break; + case Instr::FetchAndSubscribe: + { + const Register &input = registers[instr->fetchAndSubscribe.objectReg]; + Register &output = registers[instr->fetchAndSubscribe.output]; + + if (input.isUndefined()) { + throwException(instr->fetchAndSubscribe.exceptionId, error, program, context); + return; + } + + QObject *object = input.getQObject(); + if (!object) { + output.setUndefined(); + } else { + int subIdx = instr->fetchAndSubscribe.subscription; + QDeclarativeCompiledBindingsPrivate::Subscription *sub = 0; + if (subIdx != -1) { + sub = (subscriptions + subIdx); + sub->target = q; + sub->targetMethod = methodCount + subIdx; + } + fastProperties()->accessor(instr->fetchAndSubscribe.function)(object, output.typeDataPtr(), sub); + } + } + break; + case Instr::LoadId: registers[instr->load.reg].setQObject(context->idValues[instr->load.index].data()); break; @@ -2376,29 +2422,41 @@ bool QDeclarativeBindingCompilerPrivate::buildName(QStringList &name, return true; } - bool QDeclarativeBindingCompilerPrivate::fetch(Result &rv, const QMetaObject *mo, int reg, - int idx, const QStringList &subName, QDeclarativeJS::AST::ExpressionNode *node) + int idx, const QStringList &subName, + QDeclarativeJS::AST::ExpressionNode *node) { QMetaProperty prop = mo->property(idx); rv.metaObject = 0; rv.type = 0; - if (subscription(subName, &rv) && prop.hasNotifySignal() && prop.notifySignalIndex() != -1) { - Instr sub; - sub.common.type = Instr::Subscribe; - sub.subscribe.offset = subscriptionIndex(subName); - sub.subscribe.reg = reg; - sub.subscribe.index = prop.notifySignalIndex(); - bytecode << sub; - } + int fastFetchIndex = fastProperties()->accessorIndexForProperty(mo, idx); Instr fetch; - fetch.common.type = Instr::Fetch; - fetch.fetch.objectReg = reg; - fetch.fetch.index = idx; - fetch.fetch.output = reg; - fetch.fetch.exceptionId = exceptionId(node); + + if (!qmlDisableFastProperties() && fastFetchIndex != -1) { + fetch.common.type = Instr::FetchAndSubscribe; + fetch.fetchAndSubscribe.objectReg = reg; + fetch.fetchAndSubscribe.output = reg; + fetch.fetchAndSubscribe.function = fastFetchIndex; + fetch.fetchAndSubscribe.subscription = subscriptionIndex(subName); + fetch.fetchAndSubscribe.exceptionId = exceptionId(node); + } else { + if (subscription(subName, &rv) && prop.hasNotifySignal() && prop.notifySignalIndex() != -1) { + Instr sub; + sub.common.type = Instr::Subscribe; + sub.subscribe.offset = subscriptionIndex(subName); + sub.subscribe.reg = reg; + sub.subscribe.index = prop.notifySignalIndex(); + bytecode << sub; + } + + fetch.common.type = Instr::Fetch; + fetch.fetch.objectReg = reg; + fetch.fetch.index = idx; + fetch.fetch.output = reg; + fetch.fetch.exceptionId = exceptionId(node); + } rv.type = prop.userType(); rv.metaObject = engine->metaObjectForType(rv.type); diff --git a/src/declarative/qml/qml.pri b/src/declarative/qml/qml.pri index 49888c3..fc8ba50 100644 --- a/src/declarative/qml/qml.pri +++ b/src/declarative/qml/qml.pri @@ -31,6 +31,7 @@ SOURCES += \ $$PWD/qdeclarativerewrite.cpp \ $$PWD/qdeclarativevaluetype.cpp \ $$PWD/qdeclarativecompiledbindings.cpp \ + $$PWD/qdeclarativefastproperties.cpp \ $$PWD/qdeclarativexmlhttprequest.cpp \ $$PWD/qdeclarativesqldatabase.cpp \ $$PWD/qmetaobjectbuilder.cpp \ @@ -103,6 +104,7 @@ HEADERS += \ $$PWD/qbitfield_p.h \ $$PWD/qdeclarativevaluetype_p.h \ $$PWD/qdeclarativecompiledbindings_p.h \ + $$PWD/qdeclarativefastproperties_p.h \ $$PWD/qdeclarativexmlhttprequest_p.h \ $$PWD/qdeclarativesqldatabase_p.h \ $$PWD/qmetaobjectbuilder_p.h \ |