summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas McGuire <thomas.mcguire.qnx@kdab.com>2012-08-24 15:28:46 +0200
committerQt by Nokia <qt-info@nokia.com>2012-08-28 06:21:58 +0200
commit0cae9f87c8ed351f605ccb31e3dda3143028a484 (patch)
treea578e40d891eca2ee95550bc3b74446bc1e8a909
parent87679b3499e68957998b98bf13b6d98b3aa8b4c3 (diff)
Reduce memory usage of QV4Bindings::Subscription by 8 bytes.
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>
-rw-r--r--src/qml/qml/v4/qv4bindings.cpp52
-rw-r--r--src/qml/qml/v4/qv4bindings_p.h16
2 files changed, 50 insertions, 18 deletions
diff --git a/src/qml/qml/v4/qv4bindings.cpp b/src/qml/qml/v4/qv4bindings.cpp
index 7d64de707f..68e9a1a643 100644
--- a/src/qml/qml/v4/qv4bindings.cpp
+++ b/src/qml/qml/v4/qv4bindings.cpp
@@ -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);
}
diff --git a/src/qml/qml/v4/qv4bindings_p.h b/src/qml/qml/v4/qv4bindings_p.h
index 04fca8529f..4053c471fa 100644
--- a/src/qml/qml/v4/qv4bindings_p.h
+++ b/src/qml/qml/v4/qv4bindings_p.h
@@ -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 **);