From 8b1b07c872bc7457ab1381c9c826d53fbc7ad359 Mon Sep 17 00:00:00 2001 From: Fabian Kosmale Date: Mon, 28 Jun 2021 16:11:07 +0200 Subject: QProperty: Avoid needlessly refetching bindingStatus If we already have the bindingStatus, we can just pass it along. Change-Id: Iaaea4f4c34e6a786899561293016ece163c26d25 Reviewed-by: Lars Knoll (cherry picked from commit 3f0a32aeb50acf17302e44dcffc3210f199de6eb) --- src/corelib/kernel/qproperty.cpp | 15 +++++++++------ src/corelib/kernel/qproperty_p.h | 6 +++--- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/src/corelib/kernel/qproperty.cpp b/src/corelib/kernel/qproperty.cpp index 0055e6a5ff..82ab3b9b59 100644 --- a/src/corelib/kernel/qproperty.cpp +++ b/src/corelib/kernel/qproperty.cpp @@ -154,7 +154,7 @@ struct QPropertyDelayedNotifications Change notifications are sent later with notify (following the logic of separating binding updates and notifications used in non-deferred updates). */ - void evaluateBindings(int index) { + void evaluateBindings(int index, QBindingStatus *status) { auto *delayed = delayedProperties + index; auto *bindingData = delayed->originalBindingData; if (!bindingData) @@ -170,7 +170,7 @@ struct QPropertyDelayedNotifications QPropertyBindingDataPointer bindingDataPointer{bindingData}; QPropertyObserverPointer observer = bindingDataPointer.firstObserver(); if (observer) - observer.evaluateBindings(); + observer.evaluateBindings(status); } /*! @@ -242,7 +242,8 @@ void Qt::beginPropertyUpdateGroup() */ void Qt::endPropertyUpdateGroup() { - QPropertyDelayedNotifications *& groupUpdateData = bindingStatus.groupUpdateData; + auto status = &bindingStatus; + QPropertyDelayedNotifications *& groupUpdateData = status->groupUpdateData; auto *data = groupUpdateData; Q_ASSERT(data->ref); if (--data->ref) @@ -252,7 +253,7 @@ void Qt::endPropertyUpdateGroup() auto start = data; while (data) { for (int i = 0; i < data->used; ++i) - data->evaluateBindings(i); + data->evaluateBindings(i, status); data = data->next; } // notify all delayed properties @@ -285,6 +286,8 @@ void QPropertyBindingPrivate::unlinkAndDeref() void QPropertyBindingPrivate::evaluateRecursive(QBindingStatus *status) { + if (!status) + status = &bindingStatus; return evaluateRecursive_inline(status); } @@ -435,9 +438,8 @@ QPropertyBindingData::QPropertyBindingData(QPropertyBindingData &&other) : d_ptr BindingEvaluationState::BindingEvaluationState(QPropertyBindingPrivate *binding, QBindingStatus *status) : binding(binding) { + Q_ASSERT(status); QBindingStatus *s = status; - if (!s) - s = &bindingStatus; // store a pointer to the currentBindingEvaluationState to avoid a TLS lookup in // the destructor (as these come with a non zero cost) currentState = &s->currentlyEvaluatingBinding; @@ -741,6 +743,7 @@ void QPropertyObserverPointer::noSelfDependencies(QPropertyBindingPrivate *bindi void QPropertyObserverPointer::evaluateBindings(QBindingStatus *status) { + Q_ASSERT(status); auto observer = const_cast(ptr); // See also comment in notify() while (observer) { diff --git a/src/corelib/kernel/qproperty_p.h b/src/corelib/kernel/qproperty_p.h index f1b6ef6aa2..e77bc4d834 100644 --- a/src/corelib/kernel/qproperty_p.h +++ b/src/corelib/kernel/qproperty_p.h @@ -114,7 +114,7 @@ struct QPropertyObserverPointer #else void noSelfDependencies(QPropertyBindingPrivate *) {} #endif - void evaluateBindings(QBindingStatus *status = nullptr); + void evaluateBindings(QBindingStatus *status); void observeProperty(QPropertyBindingDataPointer property); explicit operator bool() const { return ptr != nullptr; } @@ -133,7 +133,7 @@ namespace QtPrivate { struct BindingEvaluationState { - BindingEvaluationState(QPropertyBindingPrivate *binding, QBindingStatus *status = nullptr); + BindingEvaluationState(QPropertyBindingPrivate *binding, QBindingStatus *status); ~BindingEvaluationState() { *currentState = previousState; @@ -327,7 +327,7 @@ public: void unlinkAndDeref(); void evaluateRecursive(QBindingStatus *status = nullptr); - void Q_ALWAYS_INLINE evaluateRecursive_inline(QBindingStatus *status = nullptr); + void Q_ALWAYS_INLINE evaluateRecursive_inline(QBindingStatus *status); void notifyRecursive(); -- cgit v1.2.3