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 <ulf.hermann@qt.io>
This commit is contained in:
Lars Knoll 2020-07-08 12:35:17 +02:00
parent bbfecdee1e
commit e5a38facf6
2 changed files with 6 additions and 4 deletions

View File

@ -70,7 +70,7 @@ void QPropertyBindingPrivate::markDirtyAndNotifyObservers()
if (firstObserver)
firstObserver.notify(this, propertyDataPtr);
if (hasStaticObserver) {
if (metaType == QMetaType::fromType<bool>()) {
if (isBool) {
auto propertyPtr = reinterpret_cast<QPropertyBase *>(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<QPropertyBase *>(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<QPropertyBase *>(propertyDataPtr);
bool newValue = propertyPtr->extraBit();
changed = evaluationFunction(metaType, &newValue);

View File

@ -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)