QProperty: Don't needlessly calculate inBindingWrapper()

If there is no binding data, we don't need it. inBindingWrapper()
involves a TLS lookup.

Pick-to: 6.2
Change-Id: I829f314d708b80821e907124eef4aec758bbbc6a
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
This commit is contained in:
Ulf Hermann 2021-10-16 11:30:50 +02:00
parent 44b7a1a37b
commit 80c17af940

View File

@ -486,11 +486,11 @@ public:
void setValue(parameter_type t) void setValue(parameter_type t)
{ {
QBindingStorage *storage = qGetBindingStorage(owner()); QBindingStorage *storage = qGetBindingStorage(owner());
auto *bd = storage->bindingData(this); if (auto *bd = storage->bindingData(this)) {
// make sure we don't remove the binding if called from the bindingWrapper // make sure we don't remove the binding if called from the bindingWrapper
const bool inWrapper = inBindingWrapper(storage); if (!inBindingWrapper(storage))
if (bd && !inWrapper)
bd->removeBinding(); bd->removeBinding();
}
this->val = t; this->val = t;
} }
@ -537,20 +537,20 @@ public:
void removeBindingUnlessInWrapper() void removeBindingUnlessInWrapper()
{ {
QBindingStorage *storage = qGetBindingStorage(owner()); QBindingStorage *storage = qGetBindingStorage(owner());
auto *bd = storage->bindingData(this); if (auto *bd = storage->bindingData(this)) {
// make sure we don't remove the binding if called from the bindingWrapper // make sure we don't remove the binding if called from the bindingWrapper
const bool inWrapper = inBindingWrapper(storage); if (!inBindingWrapper(storage))
if (bd && !inWrapper)
bd->removeBinding(); bd->removeBinding();
} }
}
void notify() void notify()
{ {
QBindingStorage *storage = qGetBindingStorage(owner()); QBindingStorage *storage = qGetBindingStorage(owner());
auto bd = storage->bindingData(this, false); if (auto bd = storage->bindingData(this, false)) {
const bool inWrapper = inBindingWrapper(storage); if (!inBindingWrapper(storage))
if (bd && !inWrapper)
notify(bd); notify(bd);
}
if constexpr (!std::is_null_pointer_v<decltype(Signal)>) { if constexpr (!std::is_null_pointer_v<decltype(Signal)>) {
if constexpr (SignalTakesValue::value) if constexpr (SignalTakesValue::value)
(owner()->*Signal)(value()); (owner()->*Signal)(value());