From 93745ef34608024db92c90c8e270e441fc346eda Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Wed, 11 Aug 2021 17:20:23 +0200 Subject: [PATCH] QMetaEnum: stop playing ping-pong with *ok MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Reviewed-by: Thiago Macieira --- src/corelib/kernel/qmetaobject.cpp | 8 ++------ 1 file 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; }