Remove ExtraBit and FlagMask from QPropertyBindingData

They are not needed and removing it can simplify the code in some places
and avoid a couple of masking operations.

Pick-to: dev 6.0.0
Change-Id: I0e4241a2784026aa89deed35f408b094e89a11a0
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
This commit is contained in:
Lars Knoll 2020-11-25 13:02:56 +01:00
parent eda4c29eb2
commit b1be6e6e6f
3 changed files with 11 additions and 22 deletions

View File

@ -73,7 +73,8 @@ void QPropertyBindingDataPointer::addObserver(QPropertyObserver *observer)
observer->next->prev = &observer->next; observer->next->prev = &observer->next;
binding->firstObserver.ptr = observer; binding->firstObserver.ptr = observer;
} else { } else {
auto firstObserver = reinterpret_cast<QPropertyObserver*>(ptr->d_ptr & ~QPropertyBindingData::FlagMask); Q_ASSERT(!(ptr->d_ptr & QPropertyBindingData::BindingBit));
auto firstObserver = reinterpret_cast<QPropertyObserver*>(ptr->d_ptr);
observer->prev = reinterpret_cast<QPropertyObserver**>(&ptr->d_ptr); observer->prev = reinterpret_cast<QPropertyObserver**>(&ptr->d_ptr);
observer->next = firstObserver; observer->next = firstObserver;
if (observer->next) if (observer->next)
@ -249,14 +250,14 @@ QUntypedPropertyBinding QPropertyBindingData::setBinding(const QUntypedPropertyB
oldBinding = QPropertyBindingPrivatePtr(existingBinding); oldBinding = QPropertyBindingPrivatePtr(existingBinding);
observer = static_cast<QPropertyBindingPrivate *>(oldBinding.data())->takeObservers(); observer = static_cast<QPropertyBindingPrivate *>(oldBinding.data())->takeObservers();
static_cast<QPropertyBindingPrivate *>(oldBinding.data())->unlinkAndDeref(); static_cast<QPropertyBindingPrivate *>(oldBinding.data())->unlinkAndDeref();
d_ptr &= FlagMask; d_ptr = 0;
} else { } else {
observer = d.firstObserver(); observer = d.firstObserver();
} }
if (newBinding) { if (newBinding) {
newBinding.data()->addRef(); newBinding.data()->addRef();
d_ptr = (d_ptr & FlagMask) | reinterpret_cast<quintptr>(newBinding.data()); d_ptr = reinterpret_cast<quintptr>(newBinding.data());
d_ptr |= BindingBit; d_ptr |= BindingBit;
auto newBindingRaw = static_cast<QPropertyBindingPrivate *>(newBinding.data()); auto newBindingRaw = static_cast<QPropertyBindingPrivate *>(newBinding.data());
newBindingRaw->setDirty(true); newBindingRaw->setDirty(true);
@ -339,7 +340,7 @@ void QPropertyBindingData::removeBinding()
if (auto *existingBinding = d.bindingPtr()) { if (auto *existingBinding = d.bindingPtr()) {
auto observer = existingBinding->takeObservers(); auto observer = existingBinding->takeObservers();
d_ptr &= ExtraBit; d_ptr = 0;
if (observer) if (observer)
d.setObservers(observer.ptr); d.setObservers(observer.ptr);
existingBinding->unlinkAndDeref(); existingBinding->unlinkAndDeref();

View File

@ -70,14 +70,14 @@ struct Q_AUTOTEST_EXPORT QPropertyBindingDataPointer
QPropertyBindingPrivate *bindingPtr() const QPropertyBindingPrivate *bindingPtr() const
{ {
if (ptr->d_ptr & QtPrivate::QPropertyBindingData::BindingBit) if (ptr->d_ptr & QtPrivate::QPropertyBindingData::BindingBit)
return reinterpret_cast<QPropertyBindingPrivate*>(ptr->d_ptr & ~QtPrivate::QPropertyBindingData::FlagMask); return reinterpret_cast<QPropertyBindingPrivate*>(ptr->d_ptr - QtPrivate::QPropertyBindingData::BindingBit);
return nullptr; return nullptr;
} }
void setObservers(QPropertyObserver *observer) void setObservers(QPropertyObserver *observer)
{ {
observer->prev = reinterpret_cast<QPropertyObserver**>(&(ptr->d_ptr)); observer->prev = reinterpret_cast<QPropertyObserver**>(&(ptr->d_ptr));
ptr->d_ptr = (reinterpret_cast<quintptr>(observer) & ~QtPrivate::QPropertyBindingData::FlagMask); ptr->d_ptr = reinterpret_cast<quintptr>(observer);
} }
void fixupFirstObserverAfterMove() const; void fixupFirstObserverAfterMove() const;
void addObserver(QPropertyObserver *observer); void addObserver(QPropertyObserver *observer);
@ -315,7 +315,7 @@ inline void QPropertyBindingDataPointer::setFirstObserver(QPropertyObserver *obs
binding->firstObserver.ptr = observer; binding->firstObserver.ptr = observer;
return; return;
} }
ptr->d_ptr = reinterpret_cast<quintptr>(observer) | (ptr->d_ptr & QtPrivate::QPropertyBindingData::FlagMask); ptr->d_ptr = reinterpret_cast<quintptr>(observer);
} }
inline void QPropertyBindingDataPointer::fixupFirstObserverAfterMove() const inline void QPropertyBindingDataPointer::fixupFirstObserverAfterMove() const
@ -333,8 +333,7 @@ inline QPropertyObserverPointer QPropertyBindingDataPointer::firstObserver() con
{ {
if (auto *binding = bindingPtr()) if (auto *binding = bindingPtr())
return binding->firstObserver; return binding->firstObserver;
return { reinterpret_cast<QPropertyObserver *>(ptr->d_ptr return { reinterpret_cast<QPropertyObserver *>(ptr->d_ptr) };
& ~QtPrivate::QPropertyBindingData::FlagMask) };
} }
template<typename Class, typename T, auto Offset, auto Setter> template<typename Class, typename T, auto Offset, auto Setter>

View File

@ -229,6 +229,8 @@ public:
QPropertyBindingData &operator=(QPropertyBindingData &&other) = delete; QPropertyBindingData &operator=(QPropertyBindingData &&other) = delete;
~QPropertyBindingData(); ~QPropertyBindingData();
static inline constexpr quintptr BindingBit = 0x1; // Is d_ptr pointing to a binding (1) or list of notifiers (0)?
bool hasBinding() const { return d_ptr & BindingBit; } bool hasBinding() const { return d_ptr & BindingBit; }
QUntypedPropertyBinding setBinding(const QUntypedPropertyBinding &newBinding, QUntypedPropertyBinding setBinding(const QUntypedPropertyBinding &newBinding,
@ -244,19 +246,6 @@ public:
void registerWithCurrentlyEvaluatingBinding() const; void registerWithCurrentlyEvaluatingBinding() const;
void notifyObservers(QUntypedPropertyData *propertyDataPtr) const; void notifyObservers(QUntypedPropertyData *propertyDataPtr) const;
void setExtraBit(bool b)
{
if (b)
d_ptr |= ExtraBit;
else
d_ptr &= ~ExtraBit;
}
bool extraBit() const { return d_ptr & ExtraBit; }
static const quintptr ExtraBit = 0x1; // Used for QProperty<bool> specialization
static const quintptr BindingBit = 0x2; // Is d_ptr pointing to a binding (1) or list of notifiers (0)?
static const quintptr FlagMask = BindingBit | ExtraBit;
}; };
template <typename T, typename Tag> template <typename T, typename Tag>