diff options
author | Lars Knoll <lars.knoll@theqtcompany.com> | 2015-04-20 09:38:07 +0200 |
---|---|---|
committer | Simon Hausmann <simon.hausmann@theqtcompany.com> | 2015-06-05 10:07:50 +0000 |
commit | a775e43ae8872e344924581736c0ab933e12510d (patch) | |
tree | f02d240abb2f2c7ac410f3ae84049923a6f0969e /src/qml | |
parent | 6e1a4bf12846e6a68931a924890f54b433a42d1c (diff) |
Replace bindingType() method by a virtual getter
This removes the need to save some bits in the abstract binding
object, and should make it easier to move QQmlAbstractBinding
over to be reference counted.
Change-Id: Ib46cb3217f3dc462f1dcaa6153d90ea2f7401f48
Reviewed-by: Simon Hausmann <simon.hausmann@theqtcompany.com>
Diffstat (limited to 'src/qml')
-rw-r--r-- | src/qml/qml/qqmlabstractbinding.cpp | 13 | ||||
-rw-r--r-- | src/qml/qml/qqmlabstractbinding_p.h | 25 | ||||
-rw-r--r-- | src/qml/qml/qqmlbinding.cpp | 10 | ||||
-rw-r--r-- | src/qml/qml/qqmlobjectcreator.cpp | 2 | ||||
-rw-r--r-- | src/qml/qml/qqmlproperty.cpp | 4 | ||||
-rw-r--r-- | src/qml/qml/qqmlvaluetypeproxybinding.cpp | 7 | ||||
-rw-r--r-- | src/qml/qml/qqmlvaluetypeproxybinding_p.h | 1 |
7 files changed, 30 insertions, 32 deletions
diff --git a/src/qml/qml/qqmlabstractbinding.cpp b/src/qml/qml/qqmlabstractbinding.cpp index 04fbb16764..4a081ae0e8 100644 --- a/src/qml/qml/qqmlabstractbinding.cpp +++ b/src/qml/qml/qqmlabstractbinding.cpp @@ -39,8 +39,8 @@ QT_BEGIN_NAMESPACE -QQmlAbstractBinding::QQmlAbstractBinding(BindingType bt) - : m_nextBindingPtr(bt) +QQmlAbstractBinding::QQmlAbstractBinding() + : m_nextBinding(0) { } @@ -79,7 +79,7 @@ void QQmlAbstractBinding::addToObject() QQmlAbstractBinding *b = data->bindings; while (b && b->targetPropertyIndex() != coreIndex) b = b->nextBinding(); - Q_ASSERT(b && b->bindingType() == QQmlAbstractBinding::ValueTypeProxy); + Q_ASSERT(b && b->isValueTypeProxy()); proxy = static_cast<QQmlValueTypeProxyBinding *>(b); } @@ -126,7 +126,7 @@ void QQmlAbstractBinding::removeFromObject() vtbinding = vtbinding->nextBinding(); Q_ASSERT(vtbinding); } - Q_ASSERT(vtbinding->bindingType() == QQmlAbstractBinding::ValueTypeProxy); + Q_ASSERT(vtbinding->isValueTypeProxy()); QQmlValueTypeProxyBinding *vtproxybinding = static_cast<QQmlValueTypeProxyBinding *>(vtbinding); @@ -197,4 +197,9 @@ QString QQmlAbstractBinding::expression() const return QLatin1String("<Unknown>"); } +bool QQmlAbstractBinding::isValueTypeProxy() const +{ + return false; +} + QT_END_NAMESPACE diff --git a/src/qml/qml/qqmlabstractbinding_p.h b/src/qml/qml/qqmlabstractbinding_p.h index ccf525ef38..f72d6918a1 100644 --- a/src/qml/qml/qqmlabstractbinding_p.h +++ b/src/qml/qml/qqmlabstractbinding_p.h @@ -59,9 +59,6 @@ class Q_QML_PRIVATE_EXPORT QQmlAbstractBinding public: typedef QWeakPointer<QQmlAbstractBinding> Pointer; - enum BindingType { Binding = 0, ValueTypeProxy = 1 }; - inline BindingType bindingType() const; - void destroy() { removeFromObject(); clear(); @@ -70,6 +67,8 @@ public: virtual QString expression() const; + virtual bool isValueTypeProxy() const; + // Should return the encoded property index for the binding. Should return this value // even if the binding is not enabled or added to an object. // Encoding is: coreIndex | (valueTypeIndex << 16) @@ -90,7 +89,7 @@ public: inline QQmlAbstractBinding *nextBinding() const; protected: - QQmlAbstractBinding(BindingType); + QQmlAbstractBinding(); virtual ~QQmlAbstractBinding(); void clear(); @@ -113,14 +112,7 @@ private: inline void setNextBinding(QQmlAbstractBinding *); // Pointer to the next binding in the linked list of bindings. - // Being a pointer, the address is always aligned to at least 4 bytes, which means the last two - // bits of the pointer are free to be used for something else. They are used to store the binding - // type. The binding type serves as an index into the static vTables array, which is used instead - // of a compiler-generated vTable. Instead of virtual functions, pointers to static functions in - // the vTables array are used for dispatching. - // This saves a compiler-generated pointer to a compiler-generated vTable, and thus reduces - // the binding object size by sizeof(void*). - qintptr m_nextBindingPtr; + QQmlAbstractBinding *m_nextBinding; protected: QFlagPointer<QObject> m_target; @@ -145,17 +137,12 @@ bool QQmlAbstractBinding::isAddedToObject() const QQmlAbstractBinding *QQmlAbstractBinding::nextBinding() const { - return (QQmlAbstractBinding *)(m_nextBindingPtr & ~0x3); + return m_nextBinding; } void QQmlAbstractBinding::setNextBinding(QQmlAbstractBinding *b) { - m_nextBindingPtr = qintptr(b) | (m_nextBindingPtr & 0x3); -} - -QQmlAbstractBinding::BindingType QQmlAbstractBinding::bindingType() const -{ - return (BindingType)(m_nextBindingPtr & 0x3); + m_nextBinding = b; } QT_END_NAMESPACE diff --git a/src/qml/qml/qqmlbinding.cpp b/src/qml/qml/qqmlbinding.cpp index 3cd6707cf2..317c4172d7 100644 --- a/src/qml/qml/qqmlbinding.cpp +++ b/src/qml/qml/qqmlbinding.cpp @@ -54,7 +54,7 @@ QQmlBinding::Identifier QQmlBinding::Invalid = -1; QQmlBinding::QQmlBinding(const QString &str, QObject *obj, QQmlContext *ctxt) : QQmlJavaScriptExpression(), - QQmlAbstractBinding(Binding) + QQmlAbstractBinding() { setNotifyOnValueChanged(true); QQmlJavaScriptExpression::setContext(QQmlContextData::get(ctxt)); @@ -66,7 +66,7 @@ QQmlBinding::QQmlBinding(const QString &str, QObject *obj, QQmlContext *ctxt) QQmlBinding::QQmlBinding(const QQmlScriptString &script, QObject *obj, QQmlContext *ctxt) : QQmlJavaScriptExpression(), - QQmlAbstractBinding(Binding) + QQmlAbstractBinding() { if (ctxt && !ctxt->isValid()) return; @@ -101,7 +101,7 @@ QQmlBinding::QQmlBinding(const QQmlScriptString &script, QObject *obj, QQmlConte QQmlBinding::QQmlBinding(const QString &str, QObject *obj, QQmlContextData *ctxt) : QQmlJavaScriptExpression(), - QQmlAbstractBinding(Binding) + QQmlAbstractBinding() { setNotifyOnValueChanged(true); QQmlJavaScriptExpression::setContext(ctxt); @@ -115,7 +115,7 @@ QQmlBinding::QQmlBinding(const QString &str, QObject *obj, QQmlContextData *ctxt, const QString &url, quint16 lineNumber, quint16 columnNumber) : QQmlJavaScriptExpression(), - QQmlAbstractBinding(Binding) + QQmlAbstractBinding() { Q_UNUSED(columnNumber); setNotifyOnValueChanged(true); @@ -128,7 +128,7 @@ QQmlBinding::QQmlBinding(const QString &str, QObject *obj, QQmlBinding::QQmlBinding(const QV4::Value &functionPtr, QObject *obj, QQmlContextData *ctxt) : QQmlJavaScriptExpression(), - QQmlAbstractBinding(Binding) + QQmlAbstractBinding() { setNotifyOnValueChanged(true); QQmlJavaScriptExpression::setContext(ctxt); diff --git a/src/qml/qml/qqmlobjectcreator.cpp b/src/qml/qml/qqmlobjectcreator.cpp index 38268528c9..02618549d3 100644 --- a/src/qml/qml/qqmlobjectcreator.cpp +++ b/src/qml/qml/qqmlobjectcreator.cpp @@ -654,7 +654,7 @@ void QQmlObjectCreator::setupBindings(const QBitArray &bindingsToSkip) if (_valueTypeProperty) { QQmlAbstractBinding *binding = QQmlPropertyPrivate::binding(_bindingTarget, _valueTypeProperty->coreIndex); - if (binding && binding->bindingType() != QQmlAbstractBinding::ValueTypeProxy) { + if (binding && !binding->isValueTypeProxy()) { QQmlPropertyPrivate::removeBinding(_bindingTarget, _valueTypeProperty->coreIndex, QQmlPropertyPrivate::DestroyOldBinding); } else if (binding) { QQmlValueTypeProxyBinding *proxy = static_cast<QQmlValueTypeProxyBinding *>(binding); diff --git a/src/qml/qml/qqmlproperty.cpp b/src/qml/qml/qqmlproperty.cpp index 39af82f0eb..997859d410 100644 --- a/src/qml/qml/qqmlproperty.cpp +++ b/src/qml/qml/qqmlproperty.cpp @@ -749,7 +749,7 @@ static QQmlAbstractBinding *removeOldBinding(QObject *object, int index, QQmlPro if (!oldBinding) return 0; - if (valueTypeIndex != -1 && oldBinding->bindingType() == QQmlAbstractBinding::ValueTypeProxy) + if (valueTypeIndex != -1 && oldBinding->isValueTypeProxy()) oldBinding = static_cast<QQmlValueTypeProxyBinding *>(oldBinding)->binding(index); if (!oldBinding) @@ -810,7 +810,7 @@ QQmlPropertyPrivate::binding(QObject *object, int index) binding = binding->nextBinding(); if (binding && valueTypeIndex != -1) { - if (binding->bindingType() == QQmlAbstractBinding::ValueTypeProxy) { + if (binding->isValueTypeProxy()) { int index = QQmlPropertyData::encodeValueTypePropertyIndex(coreIndex, valueTypeIndex); binding = static_cast<QQmlValueTypeProxyBinding *>(binding)->binding(index); } diff --git a/src/qml/qml/qqmlvaluetypeproxybinding.cpp b/src/qml/qml/qqmlvaluetypeproxybinding.cpp index bf6a7d6045..0c8dd04910 100644 --- a/src/qml/qml/qqmlvaluetypeproxybinding.cpp +++ b/src/qml/qml/qqmlvaluetypeproxybinding.cpp @@ -36,7 +36,7 @@ QT_BEGIN_NAMESPACE QQmlValueTypeProxyBinding::QQmlValueTypeProxyBinding(QObject *o, int index) - : QQmlAbstractBinding(ValueTypeProxy), + : QQmlAbstractBinding(), m_bindings(0) { m_target = o; @@ -65,6 +65,11 @@ void QQmlValueTypeProxyBinding::setEnabled(bool e, QQmlPropertyPrivate::WriteFla } } +bool QQmlValueTypeProxyBinding::isValueTypeProxy() const +{ + return true; +} + QQmlAbstractBinding *QQmlValueTypeProxyBinding::binding(int propertyIndex) { QQmlAbstractBinding *binding = m_bindings; diff --git a/src/qml/qml/qqmlvaluetypeproxybinding_p.h b/src/qml/qml/qqmlvaluetypeproxybinding_p.h index f6d9c0abc1..7ddd5c1d93 100644 --- a/src/qml/qml/qqmlvaluetypeproxybinding_p.h +++ b/src/qml/qml/qqmlvaluetypeproxybinding_p.h @@ -58,6 +58,7 @@ public: void removeBindings(quint32 mask); virtual void setEnabled(bool, QQmlPropertyPrivate::WriteFlags); + virtual bool isValueTypeProxy() const; protected: ~QQmlValueTypeProxyBinding(); |