QProperty: Remove recursive notify logic

Grouped property updates have been ported to make use of the
non-recursive variant, and thus the last remaining user of recursive
notify() is gone.

Change-Id: I617db0dedc66555152a9b43514d9d8658d528f2c
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
This commit is contained in:
Fabian Kosmale 2023-02-08 09:44:47 +01:00
parent 7a415a051a
commit d926490c80
2 changed files with 12 additions and 37 deletions

View File

@ -161,7 +161,7 @@ struct QPropertyDelayedNotifications
delayed->d_ptr = 0; delayed->d_ptr = 0;
if (observer) if (observer)
observer.notify<QPropertyObserverPointer::Notify::OnlyChangeHandlers>(delayed->propertyData); observer.notify(delayed->propertyData);
} }
}; };
@ -286,22 +286,6 @@ bool QPropertyBindingPrivate::evaluateRecursive(PendingBindingObserverList &bind
return evaluateRecursive_inline(bindingObservers, status); return evaluateRecursive_inline(bindingObservers, status);
} }
void QPropertyBindingPrivate::notifyRecursive()
{
if (!pendingNotify)
return;
pendingNotify = false;
Q_ASSERT(!updating);
updating = true;
if (firstObserver) {
firstObserver.noSelfDependencies(this);
firstObserver.notify(propertyDataPtr);
}
if (hasStaticObserver)
staticObserverCallback(propertyDataPtr);
updating = false;
}
void QPropertyBindingPrivate::notifyNonRecursive(const PendingBindingObserverList &bindingObservers) void QPropertyBindingPrivate::notifyNonRecursive(const PendingBindingObserverList &bindingObservers)
{ {
notifyNonRecursive(); notifyNonRecursive();
@ -319,7 +303,7 @@ QPropertyBindingPrivate::NotificationState QPropertyBindingPrivate::notifyNonRec
updating = true; updating = true;
if (firstObserver) { if (firstObserver) {
firstObserver.noSelfDependencies(this); firstObserver.noSelfDependencies(this);
firstObserver.notifyOnlyChangeHandler(propertyDataPtr); firstObserver.notify(propertyDataPtr);
} }
if (hasStaticObserver) if (hasStaticObserver)
staticObserverCallback(propertyDataPtr); staticObserverCallback(propertyDataPtr);
@ -606,7 +590,7 @@ void QPropertyBindingData::notifyObservers(QUntypedPropertyData *propertyDataPtr
if (notifyObserver_helper(propertyDataPtr, storage, observer, bindingObservers) == Evaluated) { if (notifyObserver_helper(propertyDataPtr, storage, observer, bindingObservers) == Evaluated) {
// evaluateBindings() can trash the observers. We need to re-fetch here. // evaluateBindings() can trash the observers. We need to re-fetch here.
if (QPropertyObserverPointer observer = d.firstObserver()) if (QPropertyObserverPointer observer = d.firstObserver())
observer.notifyOnlyChangeHandler(propertyDataPtr); observer.notify(propertyDataPtr);
for (auto &&bindingObserver: bindingObservers) for (auto &&bindingObserver: bindingObservers)
bindingObserver.binding()->notifyNonRecursive(); bindingObserver.binding()->notifyNonRecursive();
} }

View File

@ -144,9 +144,7 @@ struct QPropertyObserverPointer
enum class Notify {Everything, OnlyChangeHandlers}; enum class Notify {Everything, OnlyChangeHandlers};
template<Notify notifyPolicy = Notify::Everything>
void notify(QUntypedPropertyData *propertyDataPtr); void notify(QUntypedPropertyData *propertyDataPtr);
void notifyOnlyChangeHandler(QUntypedPropertyData *propertyDataPtr);
#ifndef QT_NO_DEBUG #ifndef QT_NO_DEBUG
void noSelfDependencies(QPropertyBindingPrivate *binding); void noSelfDependencies(QPropertyBindingPrivate *binding);
#else #else
@ -371,7 +369,6 @@ public:
bool Q_ALWAYS_INLINE evaluateRecursive_inline(PendingBindingObserverList &bindingObservers, QBindingStatus *status); bool Q_ALWAYS_INLINE evaluateRecursive_inline(PendingBindingObserverList &bindingObservers, QBindingStatus *status);
void notifyRecursive();
void notifyNonRecursive(const PendingBindingObserverList &bindingObservers); void notifyNonRecursive(const PendingBindingObserverList &bindingObservers);
enum NotificationState : bool { Delayed, Sent }; enum NotificationState : bool { Delayed, Sent };
NotificationState notifyNonRecursive(); NotificationState notifyNonRecursive();
@ -632,7 +629,7 @@ public:
== QtPrivate::QPropertyBindingData::Evaluated) { == QtPrivate::QPropertyBindingData::Evaluated) {
// evaluateBindings() can trash the observers. We need to re-fetch here. // evaluateBindings() can trash the observers. We need to re-fetch here.
if (QPropertyObserverPointer observer = d.firstObserver()) if (QPropertyObserverPointer observer = d.firstObserver())
observer.notifyOnlyChangeHandler(this); observer.notify(this);
for (auto&& bindingObserver: bindingObservers) for (auto&& bindingObserver: bindingObservers)
bindingObserver.binding()->notifyNonRecursive(); bindingObserver.binding()->notifyNonRecursive();
} }
@ -834,7 +831,14 @@ inline bool QPropertyBindingPrivate::evaluateRecursive_inline(PendingBindingObse
return true; return true;
} }
template<QPropertyObserverPointer::Notify notifyPolicy> /*!
\internal
Walks through the list of property observers, and calls any ChangeHandler
found there.
It doesn't do anything with bindings, which are only handled in
QPropertyBindingPrivate::evaluateRecursive.
*/
inline void QPropertyObserverPointer::notify(QUntypedPropertyData *propertyDataPtr) inline void QPropertyObserverPointer::notify(QUntypedPropertyData *propertyDataPtr)
{ {
auto observer = const_cast<QPropertyObserver*>(ptr); auto observer = const_cast<QPropertyObserver*>(ptr);
@ -873,15 +877,7 @@ inline void QPropertyObserverPointer::notify(QUntypedPropertyData *propertyDataP
break; break;
} }
case QPropertyObserver::ObserverNotifiesBinding: case QPropertyObserver::ObserverNotifiesBinding:
{
if constexpr (notifyPolicy == Notify::Everything) {
auto bindingToNotify = observer->binding;
QPropertyObserverNodeProtector protector(observer);
bindingToNotify->notifyRecursive();
next = protector.next();
}
break; break;
}
case QPropertyObserver::ObserverIsPlaceholder: case QPropertyObserver::ObserverIsPlaceholder:
// recursion is already properly handled somewhere else // recursion is already properly handled somewhere else
break; break;
@ -895,11 +891,6 @@ inline void QPropertyObserverPointer::notify(QUntypedPropertyData *propertyDataP
} }
} }
inline void QPropertyObserverPointer::notifyOnlyChangeHandler(QUntypedPropertyData *propertyDataPtr)
{
notify<Notify::OnlyChangeHandlers>(propertyDataPtr);
}
inline QPropertyObserverNodeProtector::~QPropertyObserverNodeProtector() inline QPropertyObserverNodeProtector::~QPropertyObserverNodeProtector()
{ {
QPropertyObserverPointer d{static_cast<QPropertyObserver *>(&m_placeHolder)}; QPropertyObserverPointer d{static_cast<QPropertyObserver *>(&m_placeHolder)};