From: Aaron Kennedy Date: Tue, 14 Feb 2012 12:43:43 +0000 (+0000) Subject: Reduce the size of QDeclarativeAbstractBinding X-Git-Tag: qt-v5.0.0-alpha1~372 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=79e42fca6f2dadfa51d95489371c44640ae3033b;p=profile%2Fivi%2Fqtdeclarative.git Reduce the size of QDeclarativeAbstractBinding The weak pointer in every binding is rarely used, so we can store it in the same memory as the me ptr. Change-Id: I3ce7d767fa25cf5b6e6d30c4f022d0e94fc3ffbb Reviewed-by: Roberto Raggi --- diff --git a/src/declarative/qml/qdeclarativebinding.cpp b/src/declarative/qml/qdeclarativebinding.cpp index 1fa4594..359f169 100644 --- a/src/declarative/qml/qdeclarativebinding.cpp +++ b/src/declarative/qml/qdeclarativebinding.cpp @@ -56,14 +56,14 @@ QT_BEGIN_NAMESPACE QDeclarativeAbstractBinding::QDeclarativeAbstractBinding() -: m_object(0), m_propertyIndex(-1), m_mePtr(0), m_prevBinding(0), m_nextBinding(0) +: m_object(0), m_propertyIndex(-1), m_prevBinding(0), m_nextBinding(0) { } QDeclarativeAbstractBinding::~QDeclarativeAbstractBinding() { Q_ASSERT(m_prevBinding == 0); - Q_ASSERT(m_mePtr == 0); + Q_ASSERT(*m_mePtr == 0); } /*! @@ -173,16 +173,16 @@ static void bindingDummyDeleter(QDeclarativeAbstractBinding *) QDeclarativeAbstractBinding::Pointer QDeclarativeAbstractBinding::weakPointer() { - if (m_selfPointer.isNull()) - m_selfPointer = QSharedPointer(this, bindingDummyDeleter); + if (m_mePtr.value().isNull()) + m_mePtr.value() = QSharedPointer(this, bindingDummyDeleter); - return m_selfPointer.toWeakRef(); + return m_mePtr.value().toWeakRef(); } void QDeclarativeAbstractBinding::clear() { - if (m_mePtr) { - *m_mePtr = 0; + if (!m_mePtr.isNull()) { + **m_mePtr = 0; m_mePtr = 0; } } diff --git a/src/declarative/qml/qdeclarativebinding_p.h b/src/declarative/qml/qdeclarativebinding_p.h index 00a3800..e87cc7d 100644 --- a/src/declarative/qml/qdeclarativebinding_p.h +++ b/src/declarative/qml/qdeclarativebinding_p.h @@ -62,6 +62,8 @@ #include #include +#include + QT_BEGIN_NAMESPACE class Q_DECLARATIVE_PRIVATE_EXPORT QDeclarativeAbstractBinding @@ -90,7 +92,7 @@ public: void addToObject(QObject *, int); void removeFromObject(); - static Pointer getPointer(QDeclarativeAbstractBinding *p) { return p ? p->weakPointer() : Pointer(); } + static inline Pointer getPointer(QDeclarativeAbstractBinding *p); protected: virtual ~QDeclarativeAbstractBinding(); @@ -108,10 +110,13 @@ private: QObject *m_object; int m_propertyIndex; - QDeclarativeAbstractBinding **m_mePtr; + + typedef QSharedPointer SharedPointer; + // To save memory, we also store the rarely used weakPointer() instance in here + QPointerValuePair m_mePtr; + QDeclarativeAbstractBinding **m_prevBinding; QDeclarativeAbstractBinding *m_nextBinding; - QSharedPointer m_selfPointer; }; class QDeclarativeValueTypeProxyBinding : public QDeclarativeAbstractBinding @@ -187,6 +192,12 @@ private: Q_DECLARE_OPERATORS_FOR_FLAGS(QDeclarativeBinding::EvaluateFlags) +QDeclarativeAbstractBinding::Pointer +QDeclarativeAbstractBinding::getPointer(QDeclarativeAbstractBinding *p) +{ + return p ? p->weakPointer() : Pointer(); +} + QT_END_NAMESPACE Q_DECLARE_METATYPE(QDeclarativeBinding*)