From a75bdfda3d7f6c3963644a864cf7b69b357f9912 Mon Sep 17 00:00:00 2001 From: Andreas Buhr Date: Fri, 8 Jan 2021 14:27:52 +0100 Subject: [PATCH] Clarify variable names in QPropertyObserverPointer::notify In QPropertyObserverPointer::notify and its calling sites, variable names "alreadyKnownToHaveChanged", "knownIfPropertyChanged", "propertyChanged", and at its calling site "knownIfChanged" are used. This is confusing. This patch changes those four to "knownToHaveChanged". For the logic implemented it is not necessary to track whether we have knowledge about having changed and whether it has actually changed (if we have knowledge) separately. Change-Id: I90b86b276ab67b2ed70dba4e456cd90220588870 Reviewed-by: Fabian Kosmale --- src/corelib/kernel/qproperty.cpp | 22 +++++++++------------- src/corelib/kernel/qproperty_p.h | 2 +- 2 files changed, 10 insertions(+), 14 deletions(-) diff --git a/src/corelib/kernel/qproperty.cpp b/src/corelib/kernel/qproperty.cpp index b5f9adc92c..7b7032f433 100644 --- a/src/corelib/kernel/qproperty.cpp +++ b/src/corelib/kernel/qproperty.cpp @@ -112,15 +112,15 @@ void QPropertyBindingPrivate::markDirtyAndNotifyObservers() eagerlyUpdating = true; QScopeGuard guard([&](){eagerlyUpdating = false;}); - bool knownIfChanged = false; + bool knownToHaveChanged = false; if (requiresEagerEvaluation()) { // these are compat properties that we will need to evaluate eagerly if (!evaluateIfDirtyAndReturnTrueIfValueChanged(propertyDataPtr)) return; - knownIfChanged = true; + knownToHaveChanged = true; } if (firstObserver) - firstObserver.notify(this, propertyDataPtr, knownIfChanged); + firstObserver.notify(this, propertyDataPtr, knownToHaveChanged); if (hasStaticObserver) staticObserverCallback(propertyDataPtr); } @@ -276,7 +276,7 @@ QUntypedPropertyBinding QPropertyBindingData::setBinding(const QUntypedPropertyB newBindingRaw->setEagerlyUpdating(true); auto changed = newBindingRaw->evaluateIfDirtyAndReturnTrueIfValueChanged(propertyDataPtr); if (changed) - observer.notify(newBindingRaw, propertyDataPtr, /*alreadyKnownToHaveChanged=*/true); + observer.notify(newBindingRaw, propertyDataPtr, /*knownToHaveChanged=*/true); newBindingRaw->setEagerlyUpdating(false); } } else if (observer) { @@ -523,11 +523,8 @@ struct [[nodiscard]] QPropertyObserverNodeProtector { ObserverNotifiesChangeHandler case would not work. Thus we instead pass the knowledge of whether the value has changed we obtained when evaluating the binding eagerly along */ -void QPropertyObserverPointer::notify(QPropertyBindingPrivate *triggeringBinding, QUntypedPropertyData *propertyDataPtr, bool alreadyKnownToHaveChanged) +void QPropertyObserverPointer::notify(QPropertyBindingPrivate *triggeringBinding, QUntypedPropertyData *propertyDataPtr, bool knownToHaveChanged) { - bool knownIfPropertyChanged = alreadyKnownToHaveChanged; - bool propertyChanged = true; - auto observer = const_cast(ptr); /* * The basic idea of the loop is as follows: We iterate over all observers in the linked list, @@ -562,12 +559,11 @@ void QPropertyObserverPointer::notify(QPropertyBindingPrivate *triggeringBinding } // both evaluateIfDirtyAndReturnTrueIfValueChanged and handlerToCall might modify the list QPropertyObserverNodeProtector protector(observer); - if (!knownIfPropertyChanged && triggeringBinding) { - knownIfPropertyChanged = true; - propertyChanged = triggeringBinding->evaluateIfDirtyAndReturnTrueIfValueChanged(propertyDataPtr); + if (!knownToHaveChanged && triggeringBinding) { + if (!triggeringBinding->evaluateIfDirtyAndReturnTrueIfValueChanged(propertyDataPtr)) + return; + knownToHaveChanged = true; } - if (!propertyChanged) - return; handlerToCall(observer, propertyDataPtr); next = protector.next(); break; diff --git a/src/corelib/kernel/qproperty_p.h b/src/corelib/kernel/qproperty_p.h index 8d4d951cc6..6ff1e8e71e 100644 --- a/src/corelib/kernel/qproperty_p.h +++ b/src/corelib/kernel/qproperty_p.h @@ -104,7 +104,7 @@ struct QPropertyObserverPointer void setChangeHandler(QPropertyObserver::ChangeHandler changeHandler); void setAliasedProperty(QUntypedPropertyData *propertyPtr); - void notify(QPropertyBindingPrivate *triggeringBinding, QUntypedPropertyData *propertyDataPtr, const bool alreadyKnownToHaveChanged = false); + void notify(QPropertyBindingPrivate *triggeringBinding, QUntypedPropertyData *propertyDataPtr, bool knownToHaveChanged = false); void observeProperty(QPropertyBindingDataPointer property); explicit operator bool() const { return ptr != nullptr; }