Skip to content

Commit

Permalink
Inline the fast path for removeBinding()
Browse files Browse the repository at this point in the history
Save a function call in the common case where we don't have a binding
This makes a rather large performance difference for setters that do
not have a binding.

Change-Id: I140f29790f6fe868721a33b9fad37205e547b8e9
Reviewed-by: Fabian Kosmale <[email protected]>
(cherry picked from commit c63901c)
Reviewed-by: Ulf Hermann <[email protected]>
  • Loading branch information
laknoll authored and Inkane committed Nov 30, 2020
1 parent e095beb commit d555425
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 10 deletions.
17 changes: 9 additions & 8 deletions src/corelib/kernel/qproperty.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -328,17 +328,18 @@ void QPropertyBindingData::evaluateIfDirty(const QUntypedPropertyData *property)
binding->evaluateIfDirtyAndReturnTrueIfValueChanged(property);
}

void QPropertyBindingData::removeBinding()
void QPropertyBindingData::removeBinding_helper()
{
QPropertyBindingDataPointer d{this};

if (auto *existingBinding = d.bindingPtr()) {
auto observer = existingBinding->takeObservers();
d_ptr = 0;
if (observer)
d.setObservers(observer.ptr);
existingBinding->unlinkAndDeref();
}
auto *existingBinding = d.bindingPtr();
Q_ASSERT(existingBinding);

auto observer = existingBinding->takeObservers();
d_ptr = 0;
if (observer)
d.setObservers(observer.ptr);
existingBinding->unlinkAndDeref();
}

void QPropertyBindingData::registerWithCurrentlyEvaluatingBinding() const
Expand Down
10 changes: 8 additions & 2 deletions src/corelib/kernel/qpropertyprivate.h
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,11 @@ class Q_CORE_EXPORT QPropertyBindingData
}

void evaluateIfDirty(const QUntypedPropertyData *property) const;
void removeBinding();
void removeBinding()
{
if (hasBinding())
removeBinding_helper();
}

void registerWithCurrentlyEvaluatingBinding(QtPrivate::BindingEvaluationState *currentBinding) const
{
Expand All @@ -257,8 +261,10 @@ class Q_CORE_EXPORT QPropertyBindingData
registerWithCurrentlyEvaluatingBinding_helper(currentBinding);
}
void registerWithCurrentlyEvaluatingBinding() const;
void registerWithCurrentlyEvaluatingBinding_helper(BindingEvaluationState *currentBinding) const;
void notifyObservers(QUntypedPropertyData *propertyDataPtr) const;
private:
void registerWithCurrentlyEvaluatingBinding_helper(BindingEvaluationState *currentBinding) const;
void removeBinding_helper();
};

template <typename T, typename Tag>
Expand Down

0 comments on commit d555425

Please sign in to comment.