summaryrefslogtreecommitdiffstats
path: root/src/declarative/qml/qmlbindingoptimizations.cpp
diff options
context:
space:
mode:
authorAaron Kennedy <aaron.kennedy@nokia.com>2009-12-14 03:42:55 (GMT)
committerAaron Kennedy <aaron.kennedy@nokia.com>2009-12-14 03:42:55 (GMT)
commit8e466a30af34c5bb83e7fc591ddf569e2ec79d9f (patch)
tree8c509407be0474dea2993486afc03dccd84ec822 /src/declarative/qml/qmlbindingoptimizations.cpp
parentc71d7b264cb55bb444cea90e1efa82f0243f566d (diff)
downloadQt-8e466a30af34c5bb83e7fc591ddf569e2ec79d9f.zip
Qt-8e466a30af34c5bb83e7fc591ddf569e2ec79d9f.tar.gz
Qt-8e466a30af34c5bb83e7fc591ddf569e2ec79d9f.tar.bz2
Introduce experimental binding optimizer
Enable with QML_EXPERIMENTAL=1
Diffstat (limited to 'src/declarative/qml/qmlbindingoptimizations.cpp')
-rw-r--r--src/declarative/qml/qmlbindingoptimizations.cpp87
1 files changed, 87 insertions, 0 deletions
diff --git a/src/declarative/qml/qmlbindingoptimizations.cpp b/src/declarative/qml/qmlbindingoptimizations.cpp
index 0f2e199..120e07b 100644
--- a/src/declarative/qml/qmlbindingoptimizations.cpp
+++ b/src/declarative/qml/qmlbindingoptimizations.cpp
@@ -42,9 +42,96 @@
#include "qmlbindingoptimizations_p.h"
#include "qmlcontext_p.h"
+#include <QtDeclarative/qmlinfo.h>
+#include "qmlbindingvme_p.h"
QT_BEGIN_NAMESPACE
+int QmlBinding_Basic::reevalIndex = -1;
+
+QmlBinding_Basic::QmlBinding_Basic(QObject *target, int property,
+ const char *data, QmlRefCount *ref,
+ QObject *scope, QmlContext *context)
+: m_enabled(false), m_updating(false), m_scope(scope), m_target(target),
+ m_property(property), m_data(data)
+{
+ if (reevalIndex == -1)
+ reevalIndex = QmlBinding_Basic::staticMetaObject.indexOfSlot("reeval()");
+
+ m_config.target = this;
+ m_config.targetSlot = reevalIndex;
+ m_scope2 = m_scope;
+
+ QmlAbstractExpression::setContext(context);
+}
+
+QmlBinding_Basic::~QmlBinding_Basic()
+{
+}
+
+void QmlBinding_Basic::setEnabled(bool e, QmlMetaProperty::WriteFlags flags)
+{
+ if (e) {
+ addToObject(m_target);
+ update(flags);
+ } else {
+ removeFromObject();
+ }
+
+ QmlAbstractBinding::setEnabled(e, flags);
+
+ if (m_enabled != e) {
+ m_enabled = e;
+
+ if (e) update(flags);
+ }
+}
+
+int QmlBinding_Basic::propertyIndex()
+{
+ return m_property & 0xFFFF;
+}
+
+void QmlBinding_Basic::update(QmlMetaProperty::WriteFlags flags)
+{
+ if (!m_enabled)
+ return;
+
+ if (m_updating) {
+ qmlInfo(m_target) << tr("Binding loop detected");
+ return;
+ }
+
+ QmlContext *context = QmlAbstractExpression::context();
+ if (!context)
+ return;
+ QmlContextPrivate *cp = QmlContextPrivate::get(context);
+
+ m_updating = true;
+
+ if (m_property & 0xFFFF0000) {
+ QmlEnginePrivate *ep = QmlEnginePrivate::get(cp->engine);
+
+ QmlValueType *vt = ep->valueTypes[(m_property >> 16) & 0xFF];
+ Q_ASSERT(vt);
+ vt->read(m_target, m_property & 0xFFFF);
+
+ QObject *target = vt;
+ QmlBindingVME::run(m_data, &m_config, cp, &m_scope, &target);
+
+ vt->write(m_target, m_property & 0xFFFF, flags);
+ } else {
+ QmlBindingVME::run(m_data, &m_config, cp, &m_scope, &m_target);
+ }
+
+ m_updating = false;
+}
+
+void QmlBinding_Basic::reeval()
+{
+ update(QmlMetaProperty::DontRemoveBinding);
+}
+
/*
The QmlBinding_Id optimization handles expressions of the type: