Optimise memory usage of bound signals
authorChris Adams <christopher.adams@nokia.com>
Mon, 23 Apr 2012 07:25:48 +0000 (17:25 +1000)
committerQt by Nokia <qt-info@nokia.com>
Thu, 26 Apr 2012 00:12:36 +0000 (02:12 +0200)
We can save a few bytes per bound signal by using a flag pointer.

Change-Id: I96d23dc287722e549e21e4c5d978bed0ba2f4bed
Reviewed-by: Michael Brasser <michael.brasser@nokia.com>
src/qml/qml/qqmlboundsignal.cpp
src/qml/qml/qqmlboundsignal_p.h

index db689b0..c0475b1 100644 (file)
@@ -222,8 +222,10 @@ void QQmlAbstractBoundSignal::removeFromObject()
 
 QQmlBoundSignal::QQmlBoundSignal(QObject *scope, const QMetaMethod &signal,
                                QObject *owner)
-: m_expression(0), m_params(0), m_scope(scope), m_index(signal.methodIndex()), m_paramsValid(false), m_isEvaluating(false)
+: m_expression(0), m_params(0), m_scope(scope), m_index(signal.methodIndex())
 {
+    setParamsValid(false);
+    setIsEvaluating(false);
     addToObject(owner);
     callback = &subscriptionCallback;
     QQmlNotifierEndpoint::connect(scope, m_index);
@@ -273,15 +275,15 @@ void QQmlBoundSignal::subscriptionCallback(QQmlNotifierEndpoint *e, void **a)
     if (QQmlDebugService::isDebuggingEnabled())
         QV8DebugService::instance()->signalEmitted(QString::fromAscii(s->m_scope->metaObject()->method(s->m_index).methodSignature()));
 
-    QQmlHandlingSignalProfiler prof(s->m_scope, s->m_index, s->m_expression);
+    QQmlHandlingSignalProfiler prof(*(s->m_scope), s->m_index, s->m_expression);
 
-    s->m_isEvaluating = true;
+    s->setIsEvaluating(true);
 
-    if (!s->m_paramsValid) {
+    if (!s->paramsValid()) {
         QMetaMethod signal = s->m_scope->metaObject()->method(s->m_index);
         if (!signal.parameterTypes().isEmpty())
             s->m_params = new QQmlBoundSignalParameters(signal, s);
-        s->m_paramsValid = true;
+        s->setParamsValid(true);
     }
 
     if (s->m_params) s->m_params->setValues(a);
@@ -292,7 +294,7 @@ void QQmlBoundSignal::subscriptionCallback(QQmlNotifierEndpoint *e, void **a)
     }
     if (s->m_params) s->m_params->clearValues();
 
-    s->m_isEvaluating = false;
+    s->setIsEvaluating(false);
 }
 
 QQmlBoundSignalParameters::QQmlBoundSignalParameters(const QMetaMethod &method, 
index e411588..7ce45aa 100644 (file)
@@ -58,6 +58,7 @@
 #include <private/qqmlabstractexpression_p.h>
 #include <private/qqmljavascriptexpression_p.h>
 #include <private/qqmlnotifier_p.h>
+#include <private/qflagpointer_p.h>
 #include <private/qobject_p.h>
 
 QT_BEGIN_NAMESPACE
@@ -134,19 +135,24 @@ public:
 
     QQmlBoundSignalExpression *expression() const;
     QQmlBoundSignalExpression *setExpression(QQmlBoundSignalExpression *);
-    QObject *scope() { return m_scope; }
+    QObject *scope() { return *m_scope; }
 
     static void subscriptionCallback(QQmlNotifierEndpoint *e, void **);
 
-    bool isEvaluating() const { return m_isEvaluating; }
+    bool isEvaluating() const { return m_scope.flag(); }
 
 private:
     QQmlBoundSignalExpression *m_expression;
     QQmlBoundSignalParameters *m_params;
-    QObject *m_scope;
+    // We store some flag bits in the following flag pointer.
+    //    m_scope:flag1 - m_isEvaluating
+    //    m_scope:flag2 - m_paramsValid
+    QFlagPointer<QObject> m_scope;
     int m_index;
-    bool m_paramsValid : 1;
-    bool m_isEvaluating : 1;
+
+    void setIsEvaluating(bool v) { m_scope.setFlagValue(v); }
+    void setParamsValid(bool v) { m_scope.setFlag2Value(v); }
+    bool paramsValid() const { return m_scope.flag2(); }
 };