diff options
author | Vladimir Belyavsky <belyavskyv@gmail.com> | 2024-04-20 20:41:26 +0300 |
---|---|---|
committer | Vladimir Belyavsky <belyavskyv@gmail.com> | 2024-04-22 08:06:32 +0000 |
commit | a5ffb1559c990af1d9c7b0f20f3e3c6257195cc1 (patch) | |
tree | e31edd1d9a70435c17db57e66d95384a0fba6039 | |
parent | f854150d0a53bf774ef31746ad7875ec3abe4945 (diff) |
QQuickState: Avoid potential extra QList detach
There might be potential extra QList detach due to the use of non-const
QList iterators in QQuickState::removeAllEntriesFromRevertList().
To avoid this, we can use QList::removeIf() which doesn't detach
if there is nothing to remove and also makes the code a bit clearer.
As a drive-by change also fix the code indentation.
Change-Id: I4a1761faaf6cf30fe1e93786ba3d094fd6e87ce9
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
-rw-r--r-- | src/quick/util/qquickstate.cpp | 40 |
1 files changed, 19 insertions, 21 deletions
diff --git a/src/quick/util/qquickstate.cpp b/src/quick/util/qquickstate.cpp index 7d589cf95e..1f066270c6 100644 --- a/src/quick/util/qquickstate.cpp +++ b/src/quick/util/qquickstate.cpp @@ -419,27 +419,25 @@ void QQuickState::addEntryToRevertList(const QQuickStateAction &action) void QQuickState::removeAllEntriesFromRevertList(QObject *target) { - Q_D(QQuickState); - - if (isStateActive()) { - const auto actionMatchesTarget = [target](QQuickSimpleAction &simpleAction) { - if (simpleAction.property().object() == target) { - QQmlPropertyPrivate::removeBinding(simpleAction.property()); - simpleAction.property().write(simpleAction.value()); - if (auto binding = simpleAction.binding()) { - QQmlProperty prop = simpleAction.property(); - binding.installOn(prop); - } - - return true; - } - return false; - }; - - d->revertList.erase(std::remove_if(d->revertList.begin(), d->revertList.end(), - actionMatchesTarget), - d->revertList.end()); - } + Q_D(QQuickState); + + if (isStateActive()) { + const auto actionMatchesTarget = [target](const QQuickSimpleAction &simpleAction) { + if (simpleAction.property().object() == target) { + QQmlPropertyPrivate::removeBinding(simpleAction.property()); + simpleAction.property().write(simpleAction.value()); + if (auto binding = simpleAction.binding()) { + QQmlProperty prop = simpleAction.property(); + binding.installOn(prop); + } + + return true; + } + return false; + }; + + d->revertList.removeIf(actionMatchesTarget); + } } void QQuickState::addEntriesToRevertList(const QList<QQuickStateAction> &actionList) |