diff options
author | Lars Knoll <lars.knoll@qt.io> | 2020-11-25 13:05:37 +0100 |
---|---|---|
committer | Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> | 2020-11-27 05:46:26 +0000 |
commit | fd4619bdae00842694bda9ced334452301b239d8 (patch) | |
tree | ee95a805dc327f6af50811183b34c1facfcace4a /src | |
parent | 032105d4d27fdd5241a33268c31fc0244ddb50ea (diff) |
Inline the fast path of a few methods
No need to do function calls for the case where we return immediately
after checking a boolean.
Change-Id: I3e449850a10fcf82acb843cce6da6dfd98de32ad
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
(cherry picked from commit e165f416a752398079590161a18255f9a0058a3e)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
Diffstat (limited to 'src')
-rw-r--r-- | src/corelib/kernel/qproperty.cpp | 27 | ||||
-rw-r--r-- | src/corelib/kernel/qproperty_p.h | 11 | ||||
-rw-r--r-- | src/corelib/kernel/qpropertyprivate.h | 17 |
3 files changed, 37 insertions, 18 deletions
diff --git a/src/corelib/kernel/qproperty.cpp b/src/corelib/kernel/qproperty.cpp index 8a0b21c8f5..47a572f548 100644 --- a/src/corelib/kernel/qproperty.cpp +++ b/src/corelib/kernel/qproperty.cpp @@ -123,10 +123,9 @@ void QPropertyBindingPrivate::markDirtyAndNotifyObservers() staticObserverCallback(propertyDataPtr); } -bool QPropertyBindingPrivate::evaluateIfDirtyAndReturnTrueIfValueChanged(const QUntypedPropertyData *data) +bool QPropertyBindingPrivate::evaluateIfDirtyAndReturnTrueIfValueChanged_helper(const QUntypedPropertyData *data, QBindingStatus *status) { - if (!dirty) - return false; + Q_ASSERT(dirty); if (updating) { error = QPropertyBindingError(QPropertyBindingError::BindingLoop); @@ -144,7 +143,7 @@ bool QPropertyBindingPrivate::evaluateIfDirtyAndReturnTrueIfValueChanged(const Q QPropertyBindingPrivatePtr keepAlive {this}; QScopedValueRollback<bool> updateGuard(updating, true); - BindingEvaluationState evaluationFrame(this); + BindingEvaluationState evaluationFrame(this, status); bool changed = false; @@ -288,22 +287,17 @@ QPropertyBindingData::QPropertyBindingData(QPropertyBindingData &&other) : d_ptr d.fixupFirstObserverAfterMove(); } -QPropertyBindingPrivate *QPropertyBindingData::binding() const -{ - QPropertyBindingDataPointer d{this}; - if (auto binding = d.bindingPtr()) - return binding; - return nullptr; -} - static thread_local QBindingStatus bindingStatus; -BindingEvaluationState::BindingEvaluationState(QPropertyBindingPrivate *binding) +BindingEvaluationState::BindingEvaluationState(QPropertyBindingPrivate *binding, QBindingStatus *status) : binding(binding) { + QBindingStatus *s = status; + if (!s) + s = &bindingStatus; // store a pointer to the currentBindingEvaluationState to avoid a TLS lookup in // the destructor (as these come with a non zero cost) - currentState = &bindingStatus.currentlyEvaluatingBinding; + currentState = &s->currentlyEvaluatingBinding; previousState = *currentState; *currentState = this; binding->clearDependencyObservers(); @@ -352,7 +346,12 @@ void QPropertyBindingData::registerWithCurrentlyEvaluatingBinding() const auto currentState = bindingStatus.currentlyEvaluatingBinding; if (!currentState) return; + registerWithCurrentlyEvaluatingBinding_helper(currentState); +} + +void QPropertyBindingData::registerWithCurrentlyEvaluatingBinding_helper(BindingEvaluationState *currentState) const +{ QPropertyBindingDataPointer d{this}; QPropertyObserverPointer dependencyObserver = currentState->binding->allocateDependencyObserver(); diff --git a/src/corelib/kernel/qproperty_p.h b/src/corelib/kernel/qproperty_p.h index 50bbcbc5f0..67ce9a74f2 100644 --- a/src/corelib/kernel/qproperty_p.h +++ b/src/corelib/kernel/qproperty_p.h @@ -123,7 +123,7 @@ namespace QtPrivate { struct BindingEvaluationState { - BindingEvaluationState(QPropertyBindingPrivate *binding); + BindingEvaluationState(QPropertyBindingPrivate *binding, QBindingStatus *status = nullptr); ~BindingEvaluationState() { *currentState = previousState; @@ -270,7 +270,12 @@ public: void unlinkAndDeref(); void markDirtyAndNotifyObservers(); - bool evaluateIfDirtyAndReturnTrueIfValueChanged(const QUntypedPropertyData *data); + bool evaluateIfDirtyAndReturnTrueIfValueChanged(const QUntypedPropertyData *data, QBindingStatus *status = nullptr) + { + if (!dirty) + return false; + return evaluateIfDirtyAndReturnTrueIfValueChanged_helper(data, status); + } static QPropertyBindingPrivate *get(const QUntypedPropertyBinding &binding) { return static_cast<QPropertyBindingPrivate *>(binding.d.data()); } @@ -300,6 +305,8 @@ public: delete[] reinterpret_cast<std::byte *>(priv); } } +private: + bool evaluateIfDirtyAndReturnTrueIfValueChanged_helper(const QUntypedPropertyData *data, QBindingStatus *status = nullptr); }; inline void QPropertyBindingDataPointer::setFirstObserver(QPropertyObserver *observer) diff --git a/src/corelib/kernel/qpropertyprivate.h b/src/corelib/kernel/qpropertyprivate.h index a3fe2d208e..caf08ee5ee 100644 --- a/src/corelib/kernel/qpropertyprivate.h +++ b/src/corelib/kernel/qpropertyprivate.h @@ -158,6 +158,7 @@ template <typename T> class QPropertyData; namespace QtPrivate { +struct BindingEvaluationState; struct BindingFunctionVTable { @@ -238,14 +239,26 @@ public: QPropertyObserverCallback staticObserverCallback = nullptr, QPropertyBindingWrapper bindingWrapper = nullptr); - QPropertyBindingPrivate *binding() const; + QPropertyBindingPrivate *binding() const + { + if (d_ptr & BindingBit) + return reinterpret_cast<QPropertyBindingPrivate*>(d_ptr - BindingBit); + return nullptr; + + } void evaluateIfDirty(const QUntypedPropertyData *property) const; void removeBinding(); + void registerWithCurrentlyEvaluatingBinding(QtPrivate::BindingEvaluationState *currentBinding) const + { + if (!currentBinding) + return; + registerWithCurrentlyEvaluatingBinding_helper(currentBinding); + } void registerWithCurrentlyEvaluatingBinding() const; + void registerWithCurrentlyEvaluatingBinding_helper(BindingEvaluationState *currentBinding) const; void notifyObservers(QUntypedPropertyData *propertyDataPtr) const; - }; template <typename T, typename Tag> |