Reduce memory usage of QV4Bindings::Subscription by 8 bytes.
authorThomas McGuire <thomas.mcguire.qnx@kdab.com>
Fri, 24 Aug 2012 13:28:46 +0000 (15:28 +0200)
committerQt by Nokia <qt-info@nokia.com>
Tue, 28 Aug 2012 04:21:58 +0000 (06:21 +0200)
There is no need to store the method, as it can be calculated via
pointer arithmetic.
That leaves the active flag, which now is the last bit of the bindings
pointer.

Change-Id: I17b443e63be2d950aa80ad15cc76372b415c3dd6
Reviewed-by: Matthew Vogt <matthew.vogt@nokia.com>
src/qml/qml/v4/qv4bindings.cpp
src/qml/qml/v4/qv4bindings_p.h

index 7d64de7..68e9a1a 100644 (file)
@@ -434,8 +434,8 @@ void QV4Bindings::Binding::disconnect()
             Binding * const binding = parent->bindings + bindingRef->binding;
             if (binding == this) {
                 Subscription * const sub = parent->subscriptions + subIndex;
-                if (sub->active) {
-                    sub->active = false;
+                if (sub->active()) {
+                    sub->setActive(false);
                     sub->disconnect();
                 }
             }
@@ -444,15 +444,42 @@ void QV4Bindings::Binding::disconnect()
 }
 
 QV4Bindings::Subscription::Subscription()
-    : bindings(0), method(-1), active(false)
+    : m_bindings(0)
 {
     setCallback(QQmlNotifierEndpoint::QV4BindingsSubscription);
 }
 
+int QV4Bindings::Subscription::method() const
+{
+    Q_ASSERT(bindings() != 0);
+    return (this - bindings()->subscriptions);
+}
+
+void QV4Bindings::Subscription::setBindings(QV4Bindings *bindings)
+{
+    m_bindings = bindings;
+}
+
+QV4Bindings *QV4Bindings::Subscription::bindings() const
+{
+    return *m_bindings;
+}
+
+bool QV4Bindings::Subscription::active() const
+{
+    return m_bindings.flag();
+}
+
+void QV4Bindings::Subscription::setActive(bool active)
+{
+    m_bindings.setFlagValue(active);
+}
+
 void QV4BindingsSubscription_callback(QQmlNotifierEndpoint *e, void **)
 {
     QV4Bindings::Subscription *s = static_cast<QV4Bindings::Subscription *>(e);
-    s->bindings->subscriptionNotify(s->method);
+    Q_ASSERT(s->bindings());
+    s->bindings()->subscriptionNotify(s->method());
 }
 
 void QV4Bindings::subscriptionNotify(int id)
@@ -558,12 +585,11 @@ void QV4Bindings::subscribeId(QQmlContextData *p, int idIndex, int subIndex)
     sub->disconnect();
 
     if (p->idValues[idIndex]) {
-        sub->bindings = this;
-        sub->method = subIndex;
+        sub->setBindings(this);
         sub->connect(&p->idValues[idIndex].bindings);
-        sub->active = true;
+        sub->setActive(true);
     } else {
-        sub->active = false;
+        sub->setActive(false);
     }
 }
 
@@ -572,14 +598,13 @@ void QV4Bindings::subscribe(QObject *o, int notifyIndex, int subIndex, QQmlEngin
     Subscription *sub = (subscriptions + subIndex);
     if (sub->isConnected(o, notifyIndex))
         return;
-    sub->bindings = this;
-    sub->method = subIndex;
+    sub->setBindings(this);
     if (o) {
         sub->connect(o, notifyIndex, e);
-        sub->active = true;
+        sub->setActive(true);
     } else {
         sub->disconnect();
-        sub->active = false;
+        sub->setActive(false);
     }
 }
 
@@ -992,8 +1017,7 @@ void QV4Bindings::run(int instrIndex, quint32 &executedBlocks,
                     Subscription *sub = 0;
                     if (subIdx != -1) {
                         sub = (subscriptions + subIdx);
-                        sub->bindings = this;
-                        sub->method = subIdx;
+                        sub->setBindings(this);
                     }
                     sub->connect(notifier);
                 }
index 04fca85..4053c47 100644 (file)
@@ -122,11 +122,19 @@ private:
     {
     public:
         inline Subscription();
-        QV4Bindings *bindings;
-        int method:31;
 
-        // Subscriptions are not shared between bindings (anymore), so this can be a simple bool flag
-        bool active:1;
+        // Index of this Subscription into the QV4Bindings::subscriptions array.
+        // This may not be used before setBindings() was called.
+        inline int method() const;
+
+        inline void setBindings(QV4Bindings *bindings);
+        inline QV4Bindings *bindings() const;
+
+        inline bool active() const;
+        inline void setActive(bool active);
+
+        // Pointer to the parent QV4Bindings. The flag is used as the 'active' value.
+        QFlagPointer<QV4Bindings> m_bindings;
     };
     friend void QV4BindingsSubscription_callback(QQmlNotifierEndpoint *e, void **);