From 9d87348260316af729892c58bc29f159a173abf1 Mon Sep 17 00:00:00 2001 From: Ahmad Samir Date: Tue, 23 Feb 2021 00:37:11 +0200 Subject: Minor code optimisation - Use more range-for loops where appropriate - Use auto instead of the usually-long iterator type names - Use cbegin/cend(), to match the std:: containers, less confusion - Use qDeleteAll instead of a for loop - Make a QRE with a long-ish pattern static NO_CHANGELOG --- src/core/kconfigini.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'src/core/kconfigini.cpp') diff --git a/src/core/kconfigini.cpp b/src/core/kconfigini.cpp index dd24a959..8c81db8f 100644 --- a/src/core/kconfigini.cpp +++ b/src/core/kconfigini.cpp @@ -298,8 +298,8 @@ void KConfigIniBackend::writeEntries(const QByteArray &locale, QIODevice &file, { QByteArray currentGroup; bool groupIsImmutable = false; - const KEntryMapConstIterator end = map.constEnd(); - for (KEntryMapConstIterator it = map.constBegin(); it != end; ++it) { + const auto end = map.cend(); + for (auto it = map.cbegin(); it != end; ++it) { const KEntryKey &key = it.key(); // Either process the default group or all others @@ -746,13 +746,13 @@ public: QByteArray KConfigIniBackend::stringToPrintable(const QByteArray &aString, StringType type) { - if (aString.isEmpty()) { + const int len = aString.size(); + if (len == 0) { return aString; } - const int l = aString.length(); - QByteArray result; // Guesstimated that it's good to avoid data() initialization for a length of l*4 - result.resize(l * 4); // Maximum 4x as long as source string due to \x escape sequences + QByteArray result; // Guesstimated that it's good to avoid data() initialization for a length of len*4 + result.resize(len * 4); // Maximum 4x as long as source string due to \x escape sequences const char *s = aString.constData(); int i = 0; char *data = result.data(); @@ -766,7 +766,7 @@ QByteArray KConfigIniBackend::stringToPrintable(const QByteArray &aString, Strin } Utf8Char utf8; - for (; i < l; ++i /*, r++*/) { + for (; i < len; ++i) { switch (s[i]) { default: if (utf8.addByte(s[i])) { -- cgit v1.2.1