aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/qml/qqmlabstractbinding_p.h
diff options
context:
space:
mode:
authorLars Knoll <lars.knoll@theqtcompany.com>2015-04-21 16:42:56 +0200
committerSimon Hausmann <simon.hausmann@theqtcompany.com>2015-06-10 07:55:36 +0000
commit37d02d62d8d14fdaa0884f96f7840661413a95c2 (patch)
tree8e3f3dd9dafd574b99ca686e657d7e73f8f7eef5 /src/qml/qml/qqmlabstractbinding_p.h
parenteb7db5934b453eea2946ed7ae9a188c44467cf23 (diff)
Make bindings refcounted
Refcounting our bindings greatly simplifies our memory management of the objects and ensures we safely clean them all up. In addition, it allows us to remove the m_mePtr and weak reference handling from QQmlAbstractBinding as we can safely handle this through the same mechanism. Change-Id: If23ebc8be276096146952b0008b62018f5d57faf Reviewed-by: Simon Hausmann <simon.hausmann@theqtcompany.com>
Diffstat (limited to 'src/qml/qml/qqmlabstractbinding_p.h')
-rw-r--r--src/qml/qml/qqmlabstractbinding_p.h46
1 files changed, 19 insertions, 27 deletions
diff --git a/src/qml/qml/qqmlabstractbinding_p.h b/src/qml/qml/qqmlabstractbinding_p.h
index f72d6918a1..79107bb04c 100644
--- a/src/qml/qml/qqmlabstractbinding_p.h
+++ b/src/qml/qml/qqmlabstractbinding_p.h
@@ -46,6 +46,7 @@
//
#include <QtCore/qsharedpointer.h>
+#include <QtCore/qshareddata.h>
#include <private/qtqmlglobal_p.h>
#include <private/qqmlproperty_p.h>
#include <private/qpointervaluepair_p.h>
@@ -56,14 +57,12 @@ class QQmlObjectCreator;
class Q_QML_PRIVATE_EXPORT QQmlAbstractBinding
{
+protected:
+ QQmlAbstractBinding();
public:
- typedef QWeakPointer<QQmlAbstractBinding> Pointer;
+ virtual ~QQmlAbstractBinding();
- void destroy() {
- removeFromObject();
- clear();
- delete this;
- }
+ typedef QExplicitlySharedDataPointer<QQmlAbstractBinding> Ptr;
virtual QString expression() const;
@@ -83,28 +82,26 @@ public:
void addToObject();
void removeFromObject();
- static inline Pointer getPointer(QQmlAbstractBinding *p);
static void printBindingLoopError(QQmlProperty &prop);
inline QQmlAbstractBinding *nextBinding() const;
-protected:
- QQmlAbstractBinding();
- virtual ~QQmlAbstractBinding();
- void clear();
+
+ struct RefCount {
+ RefCount() : refCount(0) {}
+ int refCount;
+ void ref() { ++refCount; }
+ int deref() { return --refCount; }
+ operator int() const { return refCount; }
+ };
+ RefCount ref;
private:
friend class QQmlData;
friend class QQmlValueTypeProxyBinding;
friend class QQmlObjectCreator;
- Pointer weakPointer();
-
typedef QSharedPointer<QQmlAbstractBinding> SharedPointer;
- // To save memory, we also store the rarely used weakPointer() instance in here
- // We also use the flag bits:
- // m_mePtr.flag1: added to object
- QPointerValuePair<QQmlAbstractBinding*, SharedPointer> m_mePtr;
inline void setAddedToObject(bool v);
inline bool isAddedToObject() const;
@@ -112,32 +109,27 @@ private:
inline void setNextBinding(QQmlAbstractBinding *);
// Pointer to the next binding in the linked list of bindings.
- QQmlAbstractBinding *m_nextBinding;
+ Ptr m_nextBinding;
protected:
QFlagPointer<QObject> m_target;
int m_targetIndex;
+ bool m_isAddedToObject;
};
-QQmlAbstractBinding::Pointer
-QQmlAbstractBinding::getPointer(QQmlAbstractBinding *p)
-{
- return p ? p->weakPointer() : Pointer();
-}
-
void QQmlAbstractBinding::setAddedToObject(bool v)
{
- m_mePtr.setFlagValue(v);
+ m_isAddedToObject = v;
}
bool QQmlAbstractBinding::isAddedToObject() const
{
- return m_mePtr.flag();
+ return m_isAddedToObject;
}
QQmlAbstractBinding *QQmlAbstractBinding::nextBinding() const
{
- return m_nextBinding;
+ return m_nextBinding.data();
}
void QQmlAbstractBinding::setNextBinding(QQmlAbstractBinding *b)