summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLars Knoll <lars.knoll@qt.io>2020-11-25 13:02:56 +0100
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2020-11-27 05:45:55 +0000
commit7803dff73d20ac555e8fdfaaabdcf8e6938b04b0 (patch)
tree1c1874100620c971d22a8c901b7a3fe8eaa3cde9
parentb0139fe4b4b86b645540745df8655811e2d7531d (diff)
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. Change-Id: I0e4241a2784026aa89deed35f408b094e89a11a0 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> (cherry picked from commit b1be6e6e6f355bfcb0c3814516f6009c91d2de89) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r--src/corelib/kernel/qproperty.cpp9
-rw-r--r--src/corelib/kernel/qproperty_p.h9
-rw-r--r--src/corelib/kernel/qpropertyprivate.h15
3 files changed, 11 insertions, 22 deletions
diff --git a/src/corelib/kernel/qproperty.cpp b/src/corelib/kernel/qproperty.cpp
index 147103aed9..07658cb9de 100644
--- a/src/corelib/kernel/qproperty.cpp
+++ b/src/corelib/kernel/qproperty.cpp
@@ -74,7 +74,8 @@ void QPropertyBindingDataPointer::addObserver(QPropertyObserver *observer)
observer->next->prev = &observer->next;
binding->firstObserver.ptr = observer;
} 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->next = firstObserver;
if (observer->next)
@@ -250,14 +251,14 @@ QUntypedPropertyBinding QPropertyBindingData::setBinding(const QUntypedPropertyB
oldBinding = QPropertyBindingPrivatePtr(existingBinding);
observer = static_cast<QPropertyBindingPrivate *>(oldBinding.data())->takeObservers();
static_cast<QPropertyBindingPrivate *>(oldBinding.data())->unlinkAndDeref();
- d_ptr &= FlagMask;
+ d_ptr = 0;
} else {
observer = d.firstObserver();
}
if (newBinding) {
newBinding.data()->addRef();
- d_ptr = (d_ptr & FlagMask) | reinterpret_cast<quintptr>(newBinding.data());
+ d_ptr = reinterpret_cast<quintptr>(newBinding.data());
d_ptr |= BindingBit;
auto newBindingRaw = static_cast<QPropertyBindingPrivate *>(newBinding.data());
newBindingRaw->setDirty(true);
@@ -340,7 +341,7 @@ void QPropertyBindingData::removeBinding()
if (auto *existingBinding = d.bindingPtr()) {
auto observer = existingBinding->takeObservers();
- d_ptr &= ExtraBit;
+ d_ptr = 0;
if (observer)
d.setObservers(observer.ptr);
existingBinding->unlinkAndDeref();
diff --git a/src/corelib/kernel/qproperty_p.h b/src/corelib/kernel/qproperty_p.h
index 9a0daaee3a..fb02af714b 100644
--- a/src/corelib/kernel/qproperty_p.h
+++ b/src/corelib/kernel/qproperty_p.h
@@ -70,14 +70,14 @@ struct Q_AUTOTEST_EXPORT QPropertyBindingDataPointer
QPropertyBindingPrivate *bindingPtr() const
{
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;
}
void setObservers(QPropertyObserver *observer)
{
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 addObserver(QPropertyObserver *observer);
@@ -321,7 +321,7 @@ inline void QPropertyBindingDataPointer::setFirstObserver(QPropertyObserver *obs
binding->firstObserver.ptr = observer;
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
@@ -339,8 +339,7 @@ inline QPropertyObserverPointer QPropertyBindingDataPointer::firstObserver() con
{
if (auto *binding = bindingPtr())
return binding->firstObserver;
- return { reinterpret_cast<QPropertyObserver *>(ptr->d_ptr
- & ~QtPrivate::QPropertyBindingData::FlagMask) };
+ return { reinterpret_cast<QPropertyObserver *>(ptr->d_ptr) };
}
template<typename Class, typename T, auto Offset, auto Setter>
diff --git a/src/corelib/kernel/qpropertyprivate.h b/src/corelib/kernel/qpropertyprivate.h
index 6bac03243b..58297db107 100644
--- a/src/corelib/kernel/qpropertyprivate.h
+++ b/src/corelib/kernel/qpropertyprivate.h
@@ -225,6 +225,8 @@ public:
QPropertyBindingData &operator=(QPropertyBindingData &&other) = delete;
~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; }
QUntypedPropertyBinding setBinding(const QUntypedPropertyBinding &newBinding,
@@ -240,19 +242,6 @@ public:
void registerWithCurrentlyEvaluatingBinding() 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>