aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon Hausmann <simon.hausmann@qt.io>2020-03-04 14:54:54 +0100
committerSimon Hausmann <simon.hausmann@qt.io>2020-04-03 12:35:23 +0200
commit448b2a5d838d082c66ab649cc7b71c31761bf409 (patch)
tree17888b90b9e03eb52e2ba03611146a66a87e31a1
parentf1fd2b982a2ceae92da9b4a3875c65ed8a49560d (diff)
Replace QFlagPointer with QTaggedPointer
The latter has the advantage of allowing the use of a real type for the tag, instead of the generic flag/flag2 boolean accessors. Change-Id: Icc9e854ce4af3eb5808a4bed45aa22f377e223da Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
-rw-r--r--src/qml/qml/ftw/qfieldlist_p.h118
-rw-r--r--src/qml/qml/ftw/qflagpointer_p.h152
-rw-r--r--src/qml/qml/ftw/qlazilyallocated_p.h67
-rw-r--r--src/qml/qml/ftw/qlinkedstringhash_p.h2
-rw-r--r--src/qml/qml/ftw/qstringhash_p.h14
-rw-r--r--src/qml/qml/qqmlabstractbinding_p.h31
-rw-r--r--src/qml/qml/qqmlbinding.cpp10
-rw-r--r--src/qml/qml/qqmlbinding_p.h8
-rw-r--r--src/qml/qml/qqmlcontext_p.h1
-rw-r--r--src/qml/qml/qqmlcontextdata_p.h11
-rw-r--r--src/qml/qml/qqmljavascriptexpression.cpp2
-rw-r--r--src/qml/qml/qqmljavascriptexpression_p.h22
-rw-r--r--src/qml/qml/qqmlpropertycachevector_p.h17
-rw-r--r--src/qml/qml/qqmlvmemetaobject.cpp11
-rw-r--r--src/quick/items/qquickanimatedsprite.cpp2
-rw-r--r--src/quick/items/qquickitem.cpp5
-rw-r--r--src/quick/items/qquickitem_p.h15
17 files changed, 169 insertions, 319 deletions
diff --git a/src/qml/qml/ftw/qfieldlist_p.h b/src/qml/qml/ftw/qfieldlist_p.h
index 2bf07fb20d..66602daab2 100644
--- a/src/qml/qml/ftw/qfieldlist_p.h
+++ b/src/qml/qml/ftw/qfieldlist_p.h
@@ -52,11 +52,12 @@
//
#include <QtCore/qglobal.h>
+#include <QtCore/qtaggedpointer.h>
#include <private/qflagpointer_p.h>
// QForwardFieldList is a super simple linked list that can only prepend
-template<class N, N *N::*nextMember>
+template<class N, N *N::*nextMember, typename Tag = QtPrivate::TagInfo<N>>
class QForwardFieldList
{
public:
@@ -72,17 +73,10 @@ public:
static inline N *next(N *v);
- inline bool flag() const;
- inline void setFlag();
- inline void clearFlag();
- inline void setFlagValue(bool);
-
- inline bool flag2() const;
- inline void setFlag2();
- inline void clearFlag2();
- inline void setFlag2Value(bool);
+ inline Tag tag() const;
+ inline void setTag(Tag t);
private:
- QFlagPointer<N> _first;
+ QTaggedPointer<N, Tag> _first;
};
// QFieldList is a simple linked list, that can append and prepend and also
@@ -108,8 +102,10 @@ public:
inline void insertAfter(N *, QFieldList<N, nextMember> &);
inline void copyAndClear(QFieldList<N, nextMember> &);
- inline void copyAndClearAppend(QForwardFieldList<N, nextMember> &);
- inline void copyAndClearPrepend(QForwardFieldList<N, nextMember> &);
+ template <typename Tag>
+ inline void copyAndClearAppend(QForwardFieldList<N, nextMember, Tag> &);
+ template <typename Tag>
+ inline void copyAndClearPrepend(QForwardFieldList<N, nextMember, Tag> &);
static inline N *next(N *v);
@@ -124,21 +120,21 @@ private:
quint32 _count:31;
};
-template<class N, N *N::*nextMember>
-QForwardFieldList<N, nextMember>::QForwardFieldList()
+template<class N, N *N::*nextMember, typename Tag>
+QForwardFieldList<N, nextMember, Tag>::QForwardFieldList()
{
}
-template<class N, N *N::*nextMember>
-N *QForwardFieldList<N, nextMember>::first() const
+template<class N, N *N::*nextMember, typename Tag>
+N *QForwardFieldList<N, nextMember, Tag>::first() const
{
- return *_first;
+ return _first.data();
}
-template<class N, N *N::*nextMember>
-N *QForwardFieldList<N, nextMember>::takeFirst()
+template<class N, N *N::*nextMember, typename Tag>
+N *QForwardFieldList<N, nextMember, Tag>::takeFirst()
{
- N *value = *_first;
+ N *value = _first.data();
if (value) {
_first = next(value);
value->*nextMember = nullptr;
@@ -146,85 +142,49 @@ N *QForwardFieldList<N, nextMember>::takeFirst()
return value;
}
-template<class N, N *N::*nextMember>
-void QForwardFieldList<N, nextMember>::prepend(N *v)
+template<class N, N *N::*nextMember, typename Tag>
+void QForwardFieldList<N, nextMember, Tag>::prepend(N *v)
{
Q_ASSERT(v->*nextMember == nullptr);
- v->*nextMember = *_first;
+ v->*nextMember = _first.data();
_first = v;
}
-template<class N, N *N::*nextMember>
-bool QForwardFieldList<N, nextMember>::isEmpty() const
+template<class N, N *N::*nextMember, typename Tag>
+bool QForwardFieldList<N, nextMember, Tag>::isEmpty() const
{
return _first.isNull();
}
-template<class N, N *N::*nextMember>
-bool QForwardFieldList<N, nextMember>::isOne() const
+template<class N, N *N::*nextMember, typename Tag>
+bool QForwardFieldList<N, nextMember, Tag>::isOne() const
{
- return *_first && _first->*nextMember == 0;
+ return _first.data() && _first->*nextMember == 0;
}
-template<class N, N *N::*nextMember>
-bool QForwardFieldList<N, nextMember>::isMany() const
+template<class N, N *N::*nextMember, typename Tag>
+bool QForwardFieldList<N, nextMember, Tag>::isMany() const
{
- return *_first && _first->*nextMember != 0;
+ return _first.data() && _first->*nextMember != 0;
}
-template<class N, N *N::*nextMember>
-N *QForwardFieldList<N, nextMember>::next(N *v)
+template<class N, N *N::*nextMember, typename Tag>
+N *QForwardFieldList<N, nextMember, Tag>::next(N *v)
{
Q_ASSERT(v);
return v->*nextMember;
}
-template<class N, N *N::*nextMember>
-bool QForwardFieldList<N, nextMember>::flag() const
-{
- return _first.flag();
-}
-
-template<class N, N *N::*nextMember>
-void QForwardFieldList<N, nextMember>::setFlag()
-{
- _first.setFlag();
-}
-
-template<class N, N *N::*nextMember>
-void QForwardFieldList<N, nextMember>::clearFlag()
-{
- _first.clearFlag();
-}
-
-template<class N, N *N::*nextMember>
-void QForwardFieldList<N, nextMember>::setFlagValue(bool v)
-{
- _first.setFlagValue(v);
-}
-
-template<class N, N *N::*nextMember>
-bool QForwardFieldList<N, nextMember>::flag2() const
-{
- return _first.flag2();
-}
-
-template<class N, N *N::*nextMember>
-void QForwardFieldList<N, nextMember>::setFlag2()
+template<class N, N *N::*nextMember, typename Tag>
+Tag QForwardFieldList<N, nextMember, Tag>::tag() const
{
- _first.setFlag2();
+ return _first.tag();
}
-template<class N, N *N::*nextMember>
-void QForwardFieldList<N, nextMember>::clearFlag2()
-{
- _first.clearFlag2();
-}
-
-template<class N, N *N::*nextMember>
-void QForwardFieldList<N, nextMember>::setFlag2Value(bool v)
+template<class N, N *N::*nextMember, typename Tag>
+void QForwardFieldList<N, nextMember, Tag>::setTag(Tag t)
{
- _first.setFlag2Value(v);
+ _first.setTag(t);
}
template<class N, N *N::*nextMember>
@@ -380,7 +340,8 @@ void QFieldList<N, nextMember>::copyAndClear(QFieldList<N, nextMember> &o)
}
template<class N, N *N::*nextMember>
-void QFieldList<N, nextMember>::copyAndClearAppend(QForwardFieldList<N, nextMember> &o)
+template <typename Tag>
+void QFieldList<N, nextMember>::copyAndClearAppend(QForwardFieldList<N, nextMember, Tag> &o)
{
_first = 0;
_last = 0;
@@ -389,7 +350,8 @@ void QFieldList<N, nextMember>::copyAndClearAppend(QForwardFieldList<N, nextMemb
}
template<class N, N *N::*nextMember>
-void QFieldList<N, nextMember>::copyAndClearPrepend(QForwardFieldList<N, nextMember> &o)
+template <typename Tag>
+void QFieldList<N, nextMember>::copyAndClearPrepend(QForwardFieldList<N, nextMember, Tag> &o)
{
_first = nullptr;
_last = nullptr;
diff --git a/src/qml/qml/ftw/qflagpointer_p.h b/src/qml/qml/ftw/qflagpointer_p.h
index a10e57aeca..5cdf973352 100644
--- a/src/qml/qml/ftw/qflagpointer_p.h
+++ b/src/qml/qml/ftw/qflagpointer_p.h
@@ -66,43 +66,6 @@ template <> struct QFlagPointerAlignment<void>
};
}
-template<typename T>
-class QFlagPointer {
-public:
- inline QFlagPointer();
- inline QFlagPointer(T *);
- inline QFlagPointer(const QFlagPointer<T> &o);
-
- inline bool isNull() const;
-
- inline bool flag() const;
- inline void setFlag();
- inline void clearFlag();
- inline void setFlagValue(bool);
-
- inline bool flag2() const;
- inline void setFlag2();
- inline void clearFlag2();
- inline void setFlag2Value(bool);
-
- inline QFlagPointer<T> &operator=(const QFlagPointer &o);
- inline QFlagPointer<T> &operator=(T *);
-
- inline T *operator->() const;
- inline T *operator*() const;
-
- inline T *data() const;
-
- inline explicit operator bool() const;
-
-private:
- quintptr ptr_value = 0;
-
- static const quintptr FlagBit = 0x1;
- static const quintptr Flag2Bit = 0x2;
- static const quintptr FlagsMask = FlagBit | Flag2Bit;
-};
-
template<typename T, typename T2>
class QBiPointer {
public:
@@ -135,121 +98,6 @@ private:
static const quintptr FlagsMask = FlagBit | Flag2Bit;
};
-template<typename T>
-QFlagPointer<T>::QFlagPointer()
-{
-}
-
-template<typename T>
-QFlagPointer<T>::QFlagPointer(T *v)
-: ptr_value(quintptr(v))
-{
- Q_STATIC_ASSERT_X(Q_ALIGNOF(T) >= 4, "Type T does not have sufficient alignment");
- Q_ASSERT((ptr_value & FlagsMask) == 0);
-}
-
-template<typename T>
-QFlagPointer<T>::QFlagPointer(const QFlagPointer<T> &o)
-: ptr_value(o.ptr_value)
-{
-}
-
-template<typename T>
-bool QFlagPointer<T>::isNull() const
-{
- return 0 == (ptr_value & (~FlagsMask));
-}
-
-template<typename T>
-bool QFlagPointer<T>::flag() const
-{
- return ptr_value & FlagBit;
-}
-
-template<typename T>
-void QFlagPointer<T>::setFlag()
-{
- ptr_value |= FlagBit;
-}
-
-template<typename T>
-void QFlagPointer<T>::clearFlag()
-{
- ptr_value &= ~FlagBit;
-}
-
-template<typename T>
-void QFlagPointer<T>::setFlagValue(bool v)
-{
- if (v) setFlag();
- else clearFlag();
-}
-
-template<typename T>
-bool QFlagPointer<T>::flag2() const
-{
- return ptr_value & Flag2Bit;
-}
-
-template<typename T>
-void QFlagPointer<T>::setFlag2()
-{
- ptr_value|= Flag2Bit;
-}
-
-template<typename T>
-void QFlagPointer<T>::clearFlag2()
-{
- ptr_value &= ~Flag2Bit;
-}
-
-template<typename T>
-void QFlagPointer<T>::setFlag2Value(bool v)
-{
- if (v) setFlag2();
- else clearFlag2();
-}
-
-template<typename T>
-QFlagPointer<T> &QFlagPointer<T>::operator=(const QFlagPointer &o)
-{
- ptr_value = o.ptr_value;
- return *this;
-}
-
-template<typename T>
-QFlagPointer<T> &QFlagPointer<T>::operator=(T *o)
-{
- Q_ASSERT((quintptr(o) & FlagsMask) == 0);
-
- ptr_value = quintptr(o) | (ptr_value & FlagsMask);
- return *this;
-}
-
-template<typename T>
-T *QFlagPointer<T>::operator->() const
-{
- return (T *)(ptr_value & ~FlagsMask);
-}
-
-template<typename T>
-T *QFlagPointer<T>::operator*() const
-{
- return (T *)(ptr_value & ~FlagsMask);
-}
-
-template<typename T>
-T *QFlagPointer<T>::data() const
-{
- return (T *)(ptr_value & ~FlagsMask);
-}
-
-template<typename T>
-QFlagPointer<T>::operator bool() const
-{
- return data() != nullptr;
-}
-
template<typename T, typename T2>
QBiPointer<T, T2>::QBiPointer()
{
diff --git a/src/qml/qml/ftw/qlazilyallocated_p.h b/src/qml/qml/ftw/qlazilyallocated_p.h
index 9073e41558..2bac84afb3 100644
--- a/src/qml/qml/ftw/qlazilyallocated_p.h
+++ b/src/qml/qml/ftw/qlazilyallocated_p.h
@@ -52,12 +52,11 @@
//
#include <QtCore/qglobal.h>
-
-#include <private/qflagpointer_p.h>
+#include <QtCore/qtaggedpointer.h>
QT_BEGIN_NAMESPACE
-template<typename T>
+template<typename T, typename Tag = typename QtPrivate::TagInfo<T>::TagType>
class QLazilyAllocated {
public:
inline QLazilyAllocated();
@@ -70,73 +69,59 @@ public:
inline T &value();
inline const T &value() const;
- inline bool flag() const;
- inline void setFlag();
- inline void clearFlag();
- inline void setFlagValue(bool);
+ inline Tag tag() const;
+ inline void setTag(Tag t);
private:
- mutable QFlagPointer<T> d;
+ mutable QTaggedPointer<T, Tag> d;
};
-template<typename T>
-QLazilyAllocated<T>::QLazilyAllocated()
+template<typename T, typename Tag>
+QLazilyAllocated<T, Tag>::QLazilyAllocated()
{
}
-template<typename T>
-QLazilyAllocated<T>::~QLazilyAllocated()
+template<typename T, typename Tag>
+QLazilyAllocated<T, Tag>::~QLazilyAllocated()
{
- delete *d;
+ delete d.data();
}
-template<typename T>
-bool QLazilyAllocated<T>::isAllocated() const
+template<typename T, typename Tag>
+bool QLazilyAllocated<T, Tag>::isAllocated() const
{
return !d.isNull();
}
-template<typename T>
-T &QLazilyAllocated<T>::value()
+template<typename T, typename Tag>
+T &QLazilyAllocated<T, Tag>::value()
{
if (d.isNull()) d = new T;
- return *(*d);
+ return *d;
}
-template<typename T>
-const T &QLazilyAllocated<T>::value() const
+template<typename T, typename Tag>
+const T &QLazilyAllocated<T, Tag>::value() const
{
if (d.isNull()) d = new T;
- return *(*d);
-}
-
-template<typename T>
-T *QLazilyAllocated<T>::operator->() const
-{
return *d;
}
-template<typename T>
-bool QLazilyAllocated<T>::flag() const
-{
- return d.flag();
-}
-
-template<typename T>
-void QLazilyAllocated<T>::setFlag()
+template<typename T, typename Tag>
+T *QLazilyAllocated<T, Tag>::operator->() const
{
- d.setFlag();
+ return d.data();
}
-template<typename T>
-void QLazilyAllocated<T>::clearFlag()
+template<typename T, typename Tag>
+Tag QLazilyAllocated<T, Tag>::tag() const
{
- d.clearFlag();
+ return d.tag();
}
-template<typename T>
-void QLazilyAllocated<T>::setFlagValue(bool v)
+template<typename T, typename Tag>
+void QLazilyAllocated<T, Tag>::setTag(Tag t)
{
- d.setFlagValue(v);
+ d.setTag(t);
}
QT_END_NAMESPACE
diff --git a/src/qml/qml/ftw/qlinkedstringhash_p.h b/src/qml/qml/ftw/qlinkedstringhash_p.h
index 67ced7fbbf..495d78ea2f 100644
--- a/src/qml/qml/ftw/qlinkedstringhash_p.h
+++ b/src/qml/qml/ftw/qlinkedstringhash_p.h
@@ -223,7 +223,7 @@ public:
{
if (auto *node = iter.node()) {
QHashedString key(node->key());
- while ((node = static_cast<typename QLinkedStringHash<T>::Node *>(*node->next))) {
+ while ((node = static_cast<typename QLinkedStringHash<T>::Node *>(node->next.data()))) {
if (node->equals(key))
return QLinkedStringHash<T>::iterator(node);
}
diff --git a/src/qml/qml/ftw/qstringhash_p.h b/src/qml/qml/ftw/qstringhash_p.h
index fc73fdfa50..125e160500 100644
--- a/src/qml/qml/ftw/qstringhash_p.h
+++ b/src/qml/qml/ftw/qstringhash_p.h
@@ -56,6 +56,7 @@
#include <QtCore/qbytearray.h>
#include <QtCore/qstring.h>
+#include <QtCore/qtaggedpointer.h>
QT_BEGIN_NAMESPACE
@@ -104,7 +105,12 @@ public:
QTypedArrayData<ushort>::deallocate(arrayData);
}
- QFlagPointer<QStringHashNode> next;
+ enum Tag {
+ NodeIsCString,
+ NodeIsQString
+ };
+
+ QTaggedPointer<QStringHashNode, Tag> next;
qint32 length = 0;
quint32 hash = 0;
@@ -126,8 +132,8 @@ public:
return QHashedString(QString::fromLatin1(ckey, length), hash);
}
- bool isQString() const { return next.flag(); }
- void setQString(bool v) { if (v) next.setFlag(); else next.clearFlag(); }
+ bool isQString() const { return next.tag() == NodeIsQString; }
+ void setQString(bool v) { if (v) next.setTag(NodeIsQString); else next.setTag(NodeIsCString); }
inline qsizetype size() const { return length; }
inline const char *cStrData() const { return ckey; }
@@ -712,7 +718,7 @@ typename QStringHash<T>::Node *QStringHash<T>::findNode(const K &key) const
typename HashedForm<K>::Type hashedKey(hashedString(key));
while (node && !node->equals(hashedKey))
- node = (*node->next);
+ node = node->next.data();
return (Node *)node;
}
diff --git a/src/qml/qml/qqmlabstractbinding_p.h b/src/qml/qml/qqmlabstractbinding_p.h
index fc53be3e7b..96bb0da269 100644
--- a/src/qml/qml/qqmlabstractbinding_p.h
+++ b/src/qml/qml/qqmlabstractbinding_p.h
@@ -92,7 +92,7 @@ public:
inline QQmlAbstractBinding *nextBinding() const;
inline bool canUseAccessor() const
- { return m_nextBinding.flag2(); }
+ { return m_nextBinding.tag().testFlag(CanUseAccessor); }
struct RefCount {
RefCount() {}
@@ -103,6 +103,20 @@ public:
};
RefCount ref;
+ enum TargetTag {
+ NoTargetTag = 0x0,
+ UpdatingBinding = 0x1,
+ BindingEnabled = 0x2
+ };
+ Q_DECLARE_FLAGS(TargetTags, TargetTag)
+
+ enum NextBindingTag {
+ NoBindingTag = 0x0,
+ AddedToObject = 0x1,
+ CanUseAccessor = 0x2
+ };
+ Q_DECLARE_FLAGS(NextBindingTags, NextBindingTag)
+
protected:
friend class QQmlData;
friend class QQmlValueTypeProxyBinding;
@@ -116,24 +130,23 @@ protected:
QQmlPropertyIndex m_targetIndex;
// Pointer is the target object to which the binding binds
- // flag1 is the updating flag
- // flag2 is the enabled flag
- QFlagPointer<QObject> m_target;
+ QTaggedPointer<QObject, TargetTags> m_target;
// Pointer to the next binding in the linked list of bindings.
- // flag1 is used for addedToObject
- // flag2 indicates if an accessor is can be used (i.e. there is no interceptor on the target)
- QFlagPointer<QQmlAbstractBinding> m_nextBinding;
+ QTaggedPointer<QQmlAbstractBinding, NextBindingTags> m_nextBinding;
};
+Q_DECLARE_OPERATORS_FOR_FLAGS(QQmlAbstractBinding::TargetTags)
+Q_DECLARE_OPERATORS_FOR_FLAGS(QQmlAbstractBinding::NextBindingTags)
+
void QQmlAbstractBinding::setAddedToObject(bool v)
{
- m_nextBinding.setFlagValue(v);
+ m_nextBinding.setTag(m_nextBinding.tag().setFlag(AddedToObject, v));
}
bool QQmlAbstractBinding::isAddedToObject() const
{
- return m_nextBinding.flag();
+ return m_nextBinding.tag().testFlag(AddedToObject);
}
QQmlAbstractBinding *QQmlAbstractBinding::nextBinding() const
diff --git a/src/qml/qml/qqmlbinding.cpp b/src/qml/qml/qqmlbinding.cpp
index 0dcc17d9e8..7de94fe3d5 100644
--- a/src/qml/qml/qqmlbinding.cpp
+++ b/src/qml/qml/qqmlbinding.cpp
@@ -232,7 +232,7 @@ protected:
QQmlPropertyData *pd = nullptr;
getPropertyData(&pd, nullptr);
QQmlBinding *thisPtr = this;
- pd->writeProperty(*m_target, &thisPtr, flags);
+ pd->writeProperty(m_target.data(), &thisPtr, flags);
}
};
@@ -546,10 +546,10 @@ void QQmlBinding::setEnabled(bool e, QQmlPropertyData::WriteFlags flags)
setEnabledFlag(e);
setNotifyOnValueChanged(e);
- m_nextBinding.setFlag2(); // Always use accessors, only not when:
+ m_nextBinding.setTag(m_nextBinding.tag().setFlag(CanUseAccessor)); // Always use accessors, only not when:
if (auto interceptorMetaObject = QQmlInterceptorMetaObject::get(targetObject())) {
if (!m_targetIndex.isValid() || interceptorMetaObject->intercepts(m_targetIndex))
- m_nextBinding.clearFlag2();
+ m_nextBinding.setTag(m_nextBinding.tag().setFlag(CanUseAccessor, false));
}
if (e && !wasEnabled)
@@ -606,7 +606,7 @@ bool QQmlBinding::setTarget(QObject *object, const QQmlPropertyData &core, const
}
m_targetIndex = QQmlPropertyIndex(coreIndex, valueTypeIndex);
- QQmlData *data = QQmlData::get(*m_target, true);
+ QQmlData *data = QQmlData::get(m_target.data(), true);
if (!data->propertyCache) {
data->propertyCache = QQmlEnginePrivate::get(engine())->cache(m_target->metaObject());
data->propertyCache->addref();
@@ -619,7 +619,7 @@ void QQmlBinding::getPropertyData(QQmlPropertyData **propertyData, QQmlPropertyD
{
Q_ASSERT(propertyData);
- QQmlData *data = QQmlData::get(*m_target, false);
+ QQmlData *data = QQmlData::get(m_target.data(), false);
Q_ASSERT(data);
if (Q_UNLIKELY(!data->propertyCache)) {
diff --git a/src/qml/qml/qqmlbinding_p.h b/src/qml/qml/qqmlbinding_p.h
index 8aeb87df1f..bf73c24c9e 100644
--- a/src/qml/qml/qqmlbinding_p.h
+++ b/src/qml/qml/qqmlbinding_p.h
@@ -153,22 +153,22 @@ private:
bool QQmlBinding::updatingFlag() const
{
- return m_target.flag();
+ return m_target.tag().testFlag(UpdatingBinding);
}
void QQmlBinding::setUpdatingFlag(bool v)
{
- m_target.setFlagValue(v);
+ m_target.setTag(m_target.tag().setFlag(UpdatingBinding, v));
}
bool QQmlBinding::enabledFlag() const
{
- return m_target.flag2();
+ return m_target.tag().testFlag(BindingEnabled);
}
void QQmlBinding::setEnabledFlag(bool v)
{
- m_target.setFlag2Value(v);
+ m_target.setTag(m_target.tag().setFlag(BindingEnabled, v));
}
QT_END_NAMESPACE
diff --git a/src/qml/qml/qqmlcontext_p.h b/src/qml/qml/qqmlcontext_p.h
index ca49cbf963..e1b2e9d41d 100644
--- a/src/qml/qml/qqmlcontext_p.h
+++ b/src/qml/qml/qqmlcontext_p.h
@@ -59,6 +59,7 @@
#include <QtQml/qqmllist.h>
#include <QtCore/private/qobject_p.h>
+#include <QtCore/qtaggedpointer.h>
#include <QtQml/private/qqmlrefcount_p.h>
QT_BEGIN_NAMESPACE
diff --git a/src/qml/qml/qqmlcontextdata_p.h b/src/qml/qml/qqmlcontextdata_p.h
index e31a45dea4..ccefd3a05b 100644
--- a/src/qml/qml/qqmlcontextdata_p.h
+++ b/src/qml/qml/qqmlcontextdata_p.h
@@ -278,6 +278,11 @@ private:
// id guards
struct ContextGuard : public QQmlGuard<QObject>
{
+ enum Tag {
+ NoTag,
+ ObjectWasSet
+ };
+
inline ContextGuard() : m_context(nullptr) {}
inline ContextGuard &operator=(QObject *obj);
inline void objectDestroyed(QObject *) override;
@@ -292,7 +297,7 @@ private:
private:
// Not refcounted, as it always belongs to the QQmlContextData.
- QFlagPointer<QQmlContextData> m_context;
+ QTaggedPointer<QQmlContextData, Tag> m_context;
QQmlNotifier m_bindings;
};
@@ -404,7 +409,7 @@ private:
QQmlContextData::ContextGuard &QQmlContextData::ContextGuard::operator=(QObject *obj)
{
QQmlGuard<QObject>::operator=(obj);
- m_context.setFlag();
+ m_context.setTag(ObjectWasSet);
m_bindings.notify(); // For alias connections
return *this;
}
@@ -419,7 +424,7 @@ void QQmlContextData::ContextGuard::objectDestroyed(QObject *)
bool QQmlContextData::ContextGuard::wasSet() const
{
- return m_context.flag();
+ return m_context.tag() == ObjectWasSet;
}
QT_END_NAMESPACE
diff --git a/src/qml/qml/qqmljavascriptexpression.cpp b/src/qml/qml/qqmljavascriptexpression.cpp
index 3e204c1898..0f83baa893 100644
--- a/src/qml/qml/qqmljavascriptexpression.cpp
+++ b/src/qml/qml/qqmljavascriptexpression.cpp
@@ -129,7 +129,7 @@ QString QQmlJavaScriptExpression::expressionIdentifier() const
void QQmlJavaScriptExpression::setNotifyOnValueChanged(bool v)
{
- activeGuards.setFlagValue(v);
+ activeGuards.setTag(v ? NotifyOnValueChanged : NoGuardTag);
if (!v)
clearActiveGuards();
}
diff --git a/src/qml/qml/qqmljavascriptexpression_p.h b/src/qml/qml/qqmljavascriptexpression_p.h
index b52e978938..f90b399b0a 100644
--- a/src/qml/qml/qqmljavascriptexpression_p.h
+++ b/src/qml/qml/qqmljavascriptexpression_p.h
@@ -52,6 +52,7 @@
//
#include <QtCore/qglobal.h>
+#include <QtCore/qtaggedpointer.h>
#include <QtQml/qqmlerror.h>
#include <private/qqmlengine_p.h>
@@ -175,10 +176,16 @@ protected:
// activeGuards:flag1 - notifyOnValueChanged
// activeGuards:flag2 - useSharedContext
QBiPointer<QObject, DeleteWatcher> m_scopeObject;
- QForwardFieldList<QQmlJavaScriptExpressionGuard, &QQmlJavaScriptExpressionGuard::next> activeGuards;
- void setTranslationsCaptured(bool captured) { m_error.setFlagValue(captured); }
- bool translationsCaptured() const { return m_error.flag(); }
+ enum GuardTag {
+ NoGuardTag,
+ NotifyOnValueChanged
+ };
+
+ QForwardFieldList<QQmlJavaScriptExpressionGuard, &QQmlJavaScriptExpressionGuard::next, GuardTag> activeGuards;
+
+ void setTranslationsCaptured(bool captured) { if (captured) m_error.setTag(TranslationsCaptured); else m_error.setTag(NoTag); }
+ bool translationsCaptured() const { return m_error.tag() == TranslationsCaptured; }
private:
friend class QQmlContextData;
@@ -186,8 +193,13 @@ private:
friend void QQmlJavaScriptExpressionGuard_callback(QQmlNotifierEndpoint *, void **);
friend class QQmlTranslationBinding;
+ enum Tag {
+ NoTag,
+ TranslationsCaptured
+ };
+
// m_error:flag1 translationsCapturedDuringEvaluation
- QFlagPointer<QQmlDelayedError> m_error;
+ QTaggedPointer<QQmlDelayedError> m_error;
// Not refcounted as the context will clear the expressions when destructed.
QQmlContextData *m_context;
@@ -250,7 +262,7 @@ bool QQmlJavaScriptExpression::DeleteWatcher::wasDeleted() const
bool QQmlJavaScriptExpression::notifyOnValueChanged() const
{
- return activeGuards.flag();
+ return activeGuards.tag() == NotifyOnValueChanged;
}
QObject *QQmlJavaScriptExpression::scopeObject() const
diff --git a/src/qml/qml/qqmlpropertycachevector_p.h b/src/qml/qml/qqmlpropertycachevector_p.h
index 1dff7c61a6..2e09423206 100644
--- a/src/qml/qml/qqmlpropertycachevector_p.h
+++ b/src/qml/qml/qqmlpropertycachevector_p.h
@@ -54,16 +54,23 @@
#include <private/qflagpointer_p.h>
#include <private/qqmlpropertycache_p.h>
+#include <QtCore/qtaggedpointer.h>
+
QT_BEGIN_NAMESPACE
class QQmlPropertyCacheVector
{
public:
+ enum Tag {
+ NoTag,
+ CacheNeedsVMEMetaObject
+ };
+
QQmlPropertyCacheVector() {}
QQmlPropertyCacheVector(QQmlPropertyCacheVector &&other)
: data(std::move(other.data)) {}
QQmlPropertyCacheVector &operator=(QQmlPropertyCacheVector &&other) {
- QVector<QFlagPointer<QQmlPropertyCache>> moved(std::move(other.data));
+ QVector<QTaggedPointer<QQmlPropertyCache, Tag>> moved(std::move(other.data));
data.swap(moved);
return *this;
}
@@ -80,7 +87,7 @@ public:
data.clear();
}
- void append(QQmlPropertyCache *cache) { cache->addref(); data.append(cache); }
+ void append(QQmlPropertyCache *cache) { cache->addref(); data.append(QTaggedPointer<QQmlPropertyCache, Tag>(cache)); }
QQmlPropertyCache *at(int index) const { return data.at(index).data(); }
void set(int index, const QQmlRefPointer<QQmlPropertyCache> &replacement) {
if (QQmlPropertyCache *oldCache = data.at(index).data()) {
@@ -92,11 +99,11 @@ public:
replacement->addref();
}
- void setNeedsVMEMetaObject(int index) { data[index].setFlag(); }
- bool needsVMEMetaObject(int index) const { return data.at(index).flag(); }
+ void setNeedsVMEMetaObject(int index) { data[index].setTag(CacheNeedsVMEMetaObject); }
+ bool needsVMEMetaObject(int index) const { return data.at(index).tag() == CacheNeedsVMEMetaObject; }
private:
Q_DISABLE_COPY(QQmlPropertyCacheVector)
- QVector<QFlagPointer<QQmlPropertyCache>> data;
+ QVector<QTaggedPointer<QQmlPropertyCache, Tag>> data;
};
QT_END_NAMESPACE
diff --git a/src/qml/qml/qqmlvmemetaobject.cpp b/src/qml/qml/qqmlvmemetaobject.cpp
index c107f22df5..856dda1663 100644
--- a/src/qml/qml/qqmlvmemetaobject.cpp
+++ b/src/qml/qml/qqmlvmemetaobject.cpp
@@ -204,7 +204,12 @@ public:
QQmlVMEMetaObjectEndpoint();
void tryConnect();
- QFlagPointer<QQmlVMEMetaObject> metaObject;
+ enum Tag {
+ NoTag,
+ EndPointIsConnected
+ };
+
+ QTaggedPointer<QQmlVMEMetaObject, Tag> metaObject;
};
QQmlVMEMetaObjectEndpoint::QQmlVMEMetaObjectEndpoint()
@@ -223,7 +228,7 @@ void QQmlVMEMetaObjectEndpoint::tryConnect()
Q_ASSERT(metaObject->compiledObject);
int aliasId = this - metaObject->aliasEndpoints;
- if (metaObject.flag()) {
+ if (metaObject.tag() == EndPointIsConnected) {
// This is actually notify
int sigIdx = metaObject->methodOffset() + aliasId + metaObject->compiledObject->nProperties;
metaObject->activate(metaObject->object, sigIdx, nullptr);
@@ -258,7 +263,7 @@ void QQmlVMEMetaObjectEndpoint::tryConnect()
connect(target, pd->notifyIndex(), ctxt->engine());
}
- metaObject.setFlag();
+ metaObject.setTag(EndPointIsConnected);
}
}
diff --git a/src/quick/items/qquickanimatedsprite.cpp b/src/quick/items/qquickanimatedsprite.cpp
index b285fe56ed..c227f8a89d 100644
--- a/src/quick/items/qquickanimatedsprite.cpp
+++ b/src/quick/items/qquickanimatedsprite.cpp
@@ -497,7 +497,7 @@ void QQuickAnimatedSprite::advance(int frames)
void QQuickAnimatedSprite::maybeUpdate()
{
QQuickItemPrivate *priv = QQuickItemPrivate::get(this);
- const QLazilyAllocated<QQuickItemPrivate::ExtraData> &extraData = priv->extra;
+ const auto &extraData = priv->extra;
if ((extraData.isAllocated() && extraData->effectRefCount > 0) || priv->effectiveVisible)
update();
}
diff --git a/src/quick/items/qquickitem.cpp b/src/quick/items/qquickitem.cpp
index 93f1765811..707f149baf 100644
--- a/src/quick/items/qquickitem.cpp
+++ b/src/quick/items/qquickitem.cpp
@@ -7292,10 +7292,7 @@ Qt::MouseButtons QQuickItem::acceptedMouseButtons() const
void QQuickItem::setAcceptedMouseButtons(Qt::MouseButtons buttons)
{
Q_D(QQuickItem);
- if (buttons & Qt::LeftButton)
- d->extra.setFlag();
- else
- d->extra.clearFlag();
+ d->extra.setTag(d->extra.tag().setFlag(QQuickItemPrivate::LeftMouseButtonAccepted, buttons & Qt::LeftButton));
buttons &= ~Qt::LeftButton;
if (buttons || d->extra.isAllocated())
diff --git a/src/quick/items/qquickitem_p.h b/src/quick/items/qquickitem_p.h
index 6f39f3bdd2..395dfee496 100644
--- a/src/quick/items/qquickitem_p.h
+++ b/src/quick/items/qquickitem_p.h
@@ -397,7 +397,7 @@ public:
QObjectList resourcesList;
// Although acceptedMouseButtons is inside ExtraData, we actually store
- // the LeftButton flag in the extra.flag() bit. This is because it is
+ // the LeftButton flag in the extra.tag() bit. This is because it is
// extremely common to set acceptedMouseButtons to LeftButton, but very
// rare to use any of the other buttons.
Qt::MouseButtons acceptedMouseButtons;
@@ -407,7 +407,14 @@ public:
// 26 bits padding
};
- QLazilyAllocated<ExtraData> extra;
+
+ enum ExtraDataTag {
+ NoTag = 0x1,
+ LeftMouseButtonAccepted = 0x2
+ };
+ Q_DECLARE_FLAGS(ExtraDataTags, ExtraDataTag)
+
+ QLazilyAllocated<ExtraData, ExtraDataTags> extra;
// Contains mask
QPointer<QObject> mask;
// If the mask is an Item, inform it that it's being used as a mask (true) or is no longer being used (false)
@@ -663,6 +670,8 @@ public:
virtual void updatePolish() { }
};
+Q_DECLARE_OPERATORS_FOR_FLAGS(QQuickItemPrivate::ExtraDataTags)
+
/*
Key filters can be installed on a QQuickItem, but not removed. Currently they
are only used by attached objects (which are only destroyed on Item
@@ -947,7 +956,7 @@ private:
Qt::MouseButtons QQuickItemPrivate::acceptedMouseButtons() const
{
- return ((extra.flag() ? Qt::LeftButton : Qt::MouseButton(0)) |
+ return ((extra.tag().testFlag(LeftMouseButtonAccepted) ? Qt::LeftButton : Qt::MouseButton(0)) |
(extra.isAllocated() ? extra->acceptedMouseButtons : Qt::MouseButtons{}));
}