From b038575a8995378b07e7c82cedc219c1ae40b167 Mon Sep 17 00:00:00 2001 From: Lars Knoll Date: Tue, 7 Jul 2020 16:44:07 +0200 Subject: [PATCH] Get rid of one call into the TLS when evaluating bindings Store a pointer to the TLS in the BingingEvaluationState. Like this, we can save us one TLS lookup in the destructor. Shaves off a couple of percent during binding evaluation. Change-Id: Idc9dc5b0ea202aaeb68cdc063700b8e4968753dc Reviewed-by: Ulf Hermann --- src/corelib/kernel/qproperty.cpp | 9 ++++++--- src/corelib/kernel/qproperty_p.h | 1 + 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/corelib/kernel/qproperty.cpp b/src/corelib/kernel/qproperty.cpp index f62810518b..beba05c01e 100644 --- a/src/corelib/kernel/qproperty.cpp +++ b/src/corelib/kernel/qproperty.cpp @@ -193,14 +193,17 @@ static thread_local BindingEvaluationState *currentBindingEvaluationState = null BindingEvaluationState::BindingEvaluationState(QPropertyBindingPrivate *binding) : binding(binding) { - previousState = currentBindingEvaluationState; - currentBindingEvaluationState = this; + // store a pointer to the currentBindingEvaluationState to avoid a TLS lookup in + // the destructor (as these come with a non zero cost) + currentState = ¤tBindingEvaluationState; + previousState = *currentState; + *currentState = this; binding->clearDependencyObservers(); } BindingEvaluationState::~BindingEvaluationState() { - currentBindingEvaluationState = previousState; + *currentState = previousState; } void QPropertyBase::evaluateIfDirty() diff --git a/src/corelib/kernel/qproperty_p.h b/src/corelib/kernel/qproperty_p.h index e5365f36fc..f15181a0ae 100644 --- a/src/corelib/kernel/qproperty_p.h +++ b/src/corelib/kernel/qproperty_p.h @@ -112,6 +112,7 @@ struct BindingEvaluationState ~BindingEvaluationState(); QPropertyBindingPrivate *binding; BindingEvaluationState *previousState = nullptr; + BindingEvaluationState **currentState = nullptr; }; QT_END_NAMESPACE