From 5d5343a6bc02c0df3723cb9650067e972aebe8ff Mon Sep 17 00:00:00 2001 From: Lars Knoll Date: Thu, 23 Apr 2015 21:57:06 +0200 Subject: Save one more pointer on each binding Fold the isAddedToObject flag into the nextBinding pointer. Reorder the members to avoid holes in the data. Change-Id: I0a216940f52020a5d48a6ed05cc236c248161b08 Reviewed-by: Simon Hausmann --- src/qml/qml/qqmlabstractbinding.cpp | 7 ++++--- src/qml/qml/qqmlabstractbinding_p.h | 21 ++++++++++----------- src/qml/qml/qqmlbinding.cpp | 2 +- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/qml/qml/qqmlabstractbinding.cpp b/src/qml/qml/qqmlabstractbinding.cpp index 0d281b7750..4e0763e95a 100644 --- a/src/qml/qml/qqmlabstractbinding.cpp +++ b/src/qml/qml/qqmlabstractbinding.cpp @@ -40,9 +40,7 @@ QT_BEGIN_NAMESPACE QQmlAbstractBinding::QQmlAbstractBinding() - : m_nextBinding(0), - m_targetIndex(-1), - m_isAddedToObject(false) + : m_targetIndex(-1) { Q_ASSERT(!isAddedToObject()); } @@ -51,6 +49,9 @@ QQmlAbstractBinding::~QQmlAbstractBinding() { Q_ASSERT(!ref); Q_ASSERT(!isAddedToObject()); + + if (m_nextBinding.data() && !m_nextBinding->ref.deref()) + delete m_nextBinding.data(); } /*! diff --git a/src/qml/qml/qqmlabstractbinding_p.h b/src/qml/qml/qqmlabstractbinding_p.h index 79107bb04c..dd14301aa9 100644 --- a/src/qml/qml/qqmlabstractbinding_p.h +++ b/src/qml/qml/qqmlabstractbinding_p.h @@ -96,35 +96,30 @@ public: }; RefCount ref; -private: +protected: friend class QQmlData; friend class QQmlValueTypeProxyBinding; friend class QQmlObjectCreator; - typedef QSharedPointer SharedPointer; - inline void setAddedToObject(bool v); inline bool isAddedToObject() const; inline void setNextBinding(QQmlAbstractBinding *); - // Pointer to the next binding in the linked list of bindings. - Ptr m_nextBinding; - -protected: - QFlagPointer m_target; int m_targetIndex; - bool m_isAddedToObject; + QFlagPointer m_target; + // Pointer to the next binding in the linked list of bindings. + QFlagPointer m_nextBinding; }; void QQmlAbstractBinding::setAddedToObject(bool v) { - m_isAddedToObject = v; + m_nextBinding.setFlagValue(v); } bool QQmlAbstractBinding::isAddedToObject() const { - return m_isAddedToObject; + return m_nextBinding.flag(); } QQmlAbstractBinding *QQmlAbstractBinding::nextBinding() const @@ -134,6 +129,10 @@ QQmlAbstractBinding *QQmlAbstractBinding::nextBinding() const void QQmlAbstractBinding::setNextBinding(QQmlAbstractBinding *b) { + if (b) + b->ref.ref(); + if (m_nextBinding.data() && !m_nextBinding->ref.deref()) + delete m_nextBinding.data(); m_nextBinding = b; } diff --git a/src/qml/qml/qqmlbinding.cpp b/src/qml/qml/qqmlbinding.cpp index 72f35e17d6..7581aa6654 100644 --- a/src/qml/qml/qqmlbinding.cpp +++ b/src/qml/qml/qqmlbinding.cpp @@ -191,7 +191,7 @@ void QQmlBinding::update(QQmlPropertyPrivate::WriteFlags flags) QV4::ScopedValue result(scope, QQmlJavaScriptExpression::evaluate(&isUndefined)); bool error = false; - if (!watcher.wasDeleted() && m_isAddedToObject && !hasError()) + if (!watcher.wasDeleted() && isAddedToObject() && !hasError()) error = !write(pd, result, isUndefined, flags); if (!watcher.wasDeleted()) { -- cgit v1.2.3