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:
parent
bbfecdee1e
commit
e5a38facf6
@ -70,7 +70,7 @@ void QPropertyBindingPrivate::markDirtyAndNotifyObservers()
|
|||||||
if (firstObserver)
|
if (firstObserver)
|
||||||
firstObserver.notify(this, propertyDataPtr);
|
firstObserver.notify(this, propertyDataPtr);
|
||||||
if (hasStaticObserver) {
|
if (hasStaticObserver) {
|
||||||
if (metaType == QMetaType::fromType<bool>()) {
|
if (isBool) {
|
||||||
auto propertyPtr = reinterpret_cast<QPropertyBase *>(propertyDataPtr);
|
auto propertyPtr = reinterpret_cast<QPropertyBase *>(propertyDataPtr);
|
||||||
bool oldValue = propertyPtr->extraBit();
|
bool oldValue = propertyPtr->extraBit();
|
||||||
staticObserverCallback(staticObserver, &oldValue);
|
staticObserverCallback(staticObserver, &oldValue);
|
||||||
@ -106,7 +106,7 @@ bool QPropertyBindingPrivate::evaluateIfDirtyAndReturnTrueIfValueChanged()
|
|||||||
bool changed = false;
|
bool changed = false;
|
||||||
|
|
||||||
if (hasStaticObserver && staticGuardCallback) {
|
if (hasStaticObserver && staticGuardCallback) {
|
||||||
if (metaType.id() == QMetaType::Bool) {
|
if (isBool) {
|
||||||
auto propertyPtr = reinterpret_cast<QPropertyBase *>(propertyDataPtr);
|
auto propertyPtr = reinterpret_cast<QPropertyBase *>(propertyDataPtr);
|
||||||
bool newValue = propertyPtr->extraBit();
|
bool newValue = propertyPtr->extraBit();
|
||||||
changed = staticGuardCallback(metaType, &newValue, evaluationFunction, staticObserver);
|
changed = staticGuardCallback(metaType, &newValue, evaluationFunction, staticObserver);
|
||||||
@ -116,7 +116,7 @@ bool QPropertyBindingPrivate::evaluateIfDirtyAndReturnTrueIfValueChanged()
|
|||||||
changed = staticGuardCallback(metaType, propertyDataPtr, evaluationFunction, staticObserver);
|
changed = staticGuardCallback(metaType, propertyDataPtr, evaluationFunction, staticObserver);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (metaType.id() == QMetaType::Bool) {
|
if (isBool) {
|
||||||
auto propertyPtr = reinterpret_cast<QPropertyBase *>(propertyDataPtr);
|
auto propertyPtr = reinterpret_cast<QPropertyBase *>(propertyDataPtr);
|
||||||
bool newValue = propertyPtr->extraBit();
|
bool newValue = propertyPtr->extraBit();
|
||||||
changed = evaluationFunction(metaType, &newValue);
|
changed = evaluationFunction(metaType, &newValue);
|
||||||
|
@ -72,6 +72,7 @@ private:
|
|||||||
bool dirty = false;
|
bool dirty = false;
|
||||||
bool updating = false;
|
bool updating = false;
|
||||||
bool hasStaticObserver = false;
|
bool hasStaticObserver = false;
|
||||||
|
bool isBool = false;
|
||||||
|
|
||||||
QUntypedPropertyBinding::BindingEvaluationFunction evaluationFunction;
|
QUntypedPropertyBinding::BindingEvaluationFunction evaluationFunction;
|
||||||
|
|
||||||
@ -99,7 +100,8 @@ public:
|
|||||||
|
|
||||||
QPropertyBindingPrivate(const QMetaType &metaType, QUntypedPropertyBinding::BindingEvaluationFunction evaluationFunction,
|
QPropertyBindingPrivate(const QMetaType &metaType, QUntypedPropertyBinding::BindingEvaluationFunction evaluationFunction,
|
||||||
const QPropertyBindingSourceLocation &location)
|
const QPropertyBindingSourceLocation &location)
|
||||||
: evaluationFunction(std::move(evaluationFunction))
|
: isBool(metaType.id() == QMetaType::Bool)
|
||||||
|
, evaluationFunction(std::move(evaluationFunction))
|
||||||
, inlineDependencyObservers() // Explicit initialization required because of union
|
, inlineDependencyObservers() // Explicit initialization required because of union
|
||||||
, location(location)
|
, location(location)
|
||||||
, metaType(metaType)
|
, metaType(metaType)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user