CompilerExplorer: Avoid using keys()

Instead, iterate directly over the container.

Change-Id: I6a3cb7d623e083663a11389f15b8d51599f338a3
Reviewed-by: Marcus Tillmanns <marcus.tillmanns@qt.io>
This commit is contained in:
Jarek Kobus
2024-01-07 06:29:27 +01:00
parent e901167952
commit 0c4701e45d
3 changed files with 29 additions and 36 deletions

View File

@@ -136,9 +136,8 @@ struct CompileParameters
Options &libraries(const QMap<QString, QString> &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;
}

View File

@@ -62,9 +62,8 @@ bool LibrarySelectionAspect::guiToBuffer()
QVariantMap toVariantMap(const QMap<QString, QString> &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<QString, QString> 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);
}

View File

@@ -616,21 +616,21 @@ CompilerWidget *EditorWidget::addCompiler(const std::shared_ptr<SourceSettings>
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,29 +730,25 @@ void EditorWidget::recreateEditors()
m_document->settings()->m_sources.forEachItem<SourceSettings>(
[this](const auto &sourceSettings) { addSourceEditor(sourceSettings); });
Store windowState = m_document->settings()->windowState.value();
const Store windowState = m_document->settings()->windowState.value();
if (windowState.isEmpty())
return;
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) {
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) {
QVariantMap m = v.toMap();
if (m.value("type") == "Base64") {
const QVariantMap m = v.toMap();
if (m.value("type") == "Base64")
hashMap.insert(key, QByteArray::fromBase64(m.value("value").toByteArray()));
}
}
}
}
restoreSettings(hashMap);
}
}
void EditorWidget::setupHelpWidget()
{