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>bb10
parent
d3ece0fcc2
commit
93745ef346
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue