diff options
author | Marc Mutz <marc.mutz@kdab.com> | 2021-08-11 17:20:23 +0200 |
---|---|---|
committer | Marc Mutz <marc.mutz@kdab.com> | 2021-08-18 20:31:17 +0000 |
commit | 93745ef34608024db92c90c8e270e441fc346eda (patch) | |
tree | f124c2941c1d65f52aae6f8b9e56d91ac4a3ccd1 /src/corelib/kernel/qmetaobject.cpp | |
parent | d3ece0fcc2b1fd60690bf7b6d04ad90c4eb48c0e (diff) |
QMetaEnum: stop playing ping-pong with *ok
By dropping the clause pointlessly guarding the ranged for loop against
an empty collection, we can reduce the ping-pong being played with the
*ok boolean: Just set it to false at the beginning, and only set it to
true when we reach the success-return.
Pick-to: 6.2
Change-Id: I87365146086aba427b7414e83f077096824ff56f
Reviewed-by: MÃ¥rten Nordheim <marten.nordheim@qt.io>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib/kernel/qmetaobject.cpp')
-rw-r--r-- | src/corelib/kernel/qmetaobject.cpp | 8 |
1 files changed, 2 insertions, 6 deletions
diff --git a/src/corelib/kernel/qmetaobject.cpp b/src/corelib/kernel/qmetaobject.cpp index 6bac42162b..c50d17992b 100644 --- a/src/corelib/kernel/qmetaobject.cpp +++ b/src/corelib/kernel/qmetaobject.cpp @@ -2840,12 +2840,8 @@ int QMetaEnum::keysToValue(const char *keys, bool *ok) const *ok = false; if (!mobj || !keys) return -1; - if (ok != nullptr) - *ok = true; const QString keysString = QString::fromLatin1(keys); const auto splitKeys = QStringView{keysString}.split(QLatin1Char('|')); - if (splitKeys.isEmpty()) - return 0; // ### TODO write proper code: do not allocate memory, so we can go nothrow int value = 0; for (QStringView untrimmed : splitKeys) { @@ -2870,11 +2866,11 @@ int QMetaEnum::keysToValue(const char *keys, bool *ok) const } } if (i < 0) { - if (ok != nullptr) - *ok = false; return -1; } } + if (ok != nullptr) + *ok = true; return value; } |