From e5a38facf6d69eee2a17853f9700ed79fa17430d Mon Sep 17 00:00:00 2001 From: Lars Knoll Date: Wed, 8 Jul 2020 12:35:17 +0200 Subject: [PATCH] Cache whether a property is a boolean We have the space anyway, and this cuts away another couple of percent during binding evaluation to avoid a call that checks whether the type is bool. Change-Id: I41c320f93bf0a33f0cb15962a154c59a2e47fd7a Reviewed-by: Ulf Hermann --- src/corelib/kernel/qpropertybinding.cpp | 6 +++--- src/corelib/kernel/qpropertybinding_p.h | 4 +++- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/corelib/kernel/qpropertybinding.cpp b/src/corelib/kernel/qpropertybinding.cpp index 99d17757de0..63800c4f7dc 100644 --- a/src/corelib/kernel/qpropertybinding.cpp +++ b/src/corelib/kernel/qpropertybinding.cpp @@ -70,7 +70,7 @@ void QPropertyBindingPrivate::markDirtyAndNotifyObservers() if (firstObserver) firstObserver.notify(this, propertyDataPtr); if (hasStaticObserver) { - if (metaType == QMetaType::fromType()) { + if (isBool) { auto propertyPtr = reinterpret_cast(propertyDataPtr); bool oldValue = propertyPtr->extraBit(); staticObserverCallback(staticObserver, &oldValue); @@ -106,7 +106,7 @@ bool QPropertyBindingPrivate::evaluateIfDirtyAndReturnTrueIfValueChanged() bool changed = false; if (hasStaticObserver && staticGuardCallback) { - if (metaType.id() == QMetaType::Bool) { + if (isBool) { auto propertyPtr = reinterpret_cast(propertyDataPtr); bool newValue = propertyPtr->extraBit(); changed = staticGuardCallback(metaType, &newValue, evaluationFunction, staticObserver); @@ -116,7 +116,7 @@ bool QPropertyBindingPrivate::evaluateIfDirtyAndReturnTrueIfValueChanged() changed = staticGuardCallback(metaType, propertyDataPtr, evaluationFunction, staticObserver); } } else { - if (metaType.id() == QMetaType::Bool) { + if (isBool) { auto propertyPtr = reinterpret_cast(propertyDataPtr); bool newValue = propertyPtr->extraBit(); changed = evaluationFunction(metaType, &newValue); diff --git a/src/corelib/kernel/qpropertybinding_p.h b/src/corelib/kernel/qpropertybinding_p.h index 9a18ff90158..1aa2cd864cd 100644 --- a/src/corelib/kernel/qpropertybinding_p.h +++ b/src/corelib/kernel/qpropertybinding_p.h @@ -72,6 +72,7 @@ private: bool dirty = false; bool updating = false; bool hasStaticObserver = false; + bool isBool = false; QUntypedPropertyBinding::BindingEvaluationFunction evaluationFunction; @@ -99,7 +100,8 @@ public: QPropertyBindingPrivate(const QMetaType &metaType, QUntypedPropertyBinding::BindingEvaluationFunction evaluationFunction, const QPropertyBindingSourceLocation &location) - : evaluationFunction(std::move(evaluationFunction)) + : isBool(metaType.id() == QMetaType::Bool) + , evaluationFunction(std::move(evaluationFunction)) , inlineDependencyObservers() // Explicit initialization required because of union , location(location) , metaType(metaType)