From 6971bfab440cb9b535856ed56c42a004510e7d5e Mon Sep 17 00:00:00 2001 From: Edward Welbourne Date: Wed, 1 Feb 2023 15:56:50 +0100 Subject: QPlatformTheme::removeMnemonics(): simplify space removal MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Move the unrelated advance over the removed mnemonic to before space removal and dispense with the obfuscating extra variable counting how much space we remove. Change-Id: Ibb8b1aee0d7281ae21bc9c7aa7ee84289b800f5c Reviewed-by: Richard Moe Gustavsen Reviewed-by: Tor Arne Vestbø --- src/gui/kernel/qplatformtheme.cpp | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/gui/kernel/qplatformtheme.cpp b/src/gui/kernel/qplatformtheme.cpp index 1c90e0eb01..1da438d55a 100644 --- a/src/gui/kernel/qplatformtheme.cpp +++ b/src/gui/kernel/qplatformtheme.cpp @@ -834,13 +834,12 @@ QString QPlatformTheme::removeMnemonics(const QString &original) if (l == 0) break; } else if (l >= 4 && mnemonicInParentheses(QStringView{original}.sliced(currPos, 4))) { - // Also strip any leading space before the mnemonic: - int n = 0; - while (finalDest > n && returnText.at(finalDest - n - 1).isSpace()) - ++n; - finalDest -= n; + // Advance over the matched mnemonic: currPos += 4; l -= 4; + // Also strip any leading space before it: + while (finalDest > 0 && returnText.at(finalDest - 1).isSpace()) + --finalDest; continue; } returnText[finalDest] = original.at(currPos); -- cgit v1.2.3