From 0c4701e45d5e15d29b0b774dbd36aabab4a4a848 Mon Sep 17 00:00:00 2001 From: Jarek Kobus Date: Sun, 7 Jan 2024 06:29:27 +0100 Subject: [PATCH] CompilerExplorer: Avoid using keys() Instead, iterate directly over the container. Change-Id: I6a3cb7d623e083663a11389f15b8d51599f338a3 Reviewed-by: Marcus Tillmanns --- src/plugins/compilerexplorer/api/compile.h | 5 +- .../compilerexploreraspects.cpp | 12 ++--- .../compilerexplorereditor.cpp | 48 +++++++++---------- 3 files changed, 29 insertions(+), 36 deletions(-) diff --git a/src/plugins/compilerexplorer/api/compile.h b/src/plugins/compilerexplorer/api/compile.h index 0f0493739d2..ce346fe2bde 100644 --- a/src/plugins/compilerexplorer/api/compile.h +++ b/src/plugins/compilerexplorer/api/compile.h @@ -136,9 +136,8 @@ struct CompileParameters Options &libraries(const QMap &libraries) { Libraries result; - for (const auto &key : libraries.keys()) { - result.add(key, libraries[key]); - } + for (auto it = libraries.begin(); it != libraries.end(); ++it) + result.add(it.key(), *it); obj["libraries"] = result.array; return *this; } diff --git a/src/plugins/compilerexplorer/compilerexploreraspects.cpp b/src/plugins/compilerexplorer/compilerexploreraspects.cpp index 9ca2fc5ae3c..9096b7dabeb 100644 --- a/src/plugins/compilerexplorer/compilerexploreraspects.cpp +++ b/src/plugins/compilerexplorer/compilerexploreraspects.cpp @@ -62,9 +62,8 @@ bool LibrarySelectionAspect::guiToBuffer() QVariantMap toVariantMap(const QMap &map) { QVariantMap variant; - for (const auto &key : map.keys()) - variant.insert(key, map[key]); - + for (auto it = map.begin(); it != map.end(); ++it) + variant.insert(it.key(), *it); return variant; } @@ -86,10 +85,9 @@ QVariant LibrarySelectionAspect::defaultVariantValue() const void LibrarySelectionAspect::setVariantValue(const QVariant &value, Announcement howToAnnounce) { QMap map; - Store store = storeFromVariant(value); - for (const auto &key : store.keys()) - map[stringFromKey(key)] = store[key].toString(); - + const Store store = storeFromVariant(value); + for (auto it = store.begin(); it != store.end(); ++it) + map[stringFromKey(it.key())] = it->toString(); setValue(map, howToAnnounce); } diff --git a/src/plugins/compilerexplorer/compilerexplorereditor.cpp b/src/plugins/compilerexplorer/compilerexplorereditor.cpp index 4c0af4f73ea..71d0c49503f 100644 --- a/src/plugins/compilerexplorer/compilerexplorereditor.cpp +++ b/src/plugins/compilerexplorer/compilerexplorereditor.cpp @@ -616,21 +616,21 @@ CompilerWidget *EditorWidget::addCompiler(const std::shared_ptr QVariantMap EditorWidget::windowStateCallback() { - auto settings = saveSettings(); + const auto settings = saveSettings(); QVariantMap result; - for (const Key &key : settings.keys()) { + for (auto it = settings.begin(); it != settings.end(); ++it) { // QTBUG-116339 - if (stringFromKey(key) != "State") { - result.insert(stringFromKey(key), settings.value(key)); + const QString keyString = stringFromKey(it.key()); + if (keyString != "State") { + result.insert(keyString, *it); } else { QVariantMap m; m["type"] = "Base64"; - m["value"] = settings.value(key).toByteArray().toBase64(); - result.insert(stringFromKey(key), m); + m["value"] = it->toByteArray().toBase64(); + result.insert(keyString, m); } } - return result; } @@ -730,28 +730,24 @@ void EditorWidget::recreateEditors() m_document->settings()->m_sources.forEachItem( [this](const auto &sourceSettings) { addSourceEditor(sourceSettings); }); - Store windowState = m_document->settings()->windowState.value(); + const Store windowState = m_document->settings()->windowState.value(); - if (!windowState.isEmpty()) { - Store hashMap; - for (const auto &key : windowState.keys()) { - if (key.view() != "State") - hashMap.insert(key, windowState.value(key)); - else { - QVariant v = windowState.value(key); - if (v.userType() == QMetaType::QByteArray) { - hashMap.insert(key, v); - } else if (v.userType() == QMetaType::QVariantMap) { - QVariantMap m = v.toMap(); - if (m.value("type") == "Base64") { - hashMap.insert(key, QByteArray::fromBase64(m.value("value").toByteArray())); - } - } - } + if (windowState.isEmpty()) + return; + + Store hashMap; + for (auto it = windowState.begin(); it != windowState.end(); ++it) { + const Key key = it.key(); + const QVariant v = *it; + if (key.view() != "State" || v.userType() == QMetaType::QByteArray) { + hashMap.insert(key, v); + } else if (v.userType() == QMetaType::QVariantMap) { + const QVariantMap m = v.toMap(); + if (m.value("type") == "Base64") + hashMap.insert(key, QByteArray::fromBase64(m.value("value").toByteArray())); } - - restoreSettings(hashMap); } + restoreSettings(hashMap); } void EditorWidget::setupHelpWidget()