From 2cf837801db1d529f6eee8678cdb37efde9ffa6d Mon Sep 17 00:00:00 2001 From: Gianluca Recchia Date: Thu, 17 Jan 2019 07:23:22 +0100 Subject: [PATCH] Avoid creation of temporary containers --- src/core/Config.cpp | 3 ++- src/core/CustomData.cpp | 4 +++- src/core/EntryAttachments.cpp | 4 +++- src/core/EntryAttributes.cpp | 4 +++- src/core/Merger.cpp | 3 ++- src/format/KdbxXmlReader.cpp | 4 ++-- 6 files changed, 15 insertions(+), 7 deletions(-) diff --git a/src/core/Config.cpp b/src/core/Config.cpp index edf2ece8e..14b47c34c 100644 --- a/src/core/Config.cpp +++ b/src/core/Config.cpp @@ -91,7 +91,8 @@ void Config::sync() void Config::upgrade() { - for (const auto& setting : deprecationMap.keys()) { + const auto keys = deprecationMap.keys(); + for (const auto& setting : keys) { if (m_settings->contains(setting)) { if (!deprecationMap.value(setting).isEmpty()) { // Add entry with new name and old entry's value diff --git a/src/core/CustomData.cpp b/src/core/CustomData.cpp index 835497215..86adae158 100644 --- a/src/core/CustomData.cpp +++ b/src/core/CustomData.cpp @@ -17,6 +17,8 @@ #include "CustomData.h" +#include "core/Global.h" + CustomData::CustomData(QObject* parent) : QObject(parent) { @@ -44,7 +46,7 @@ bool CustomData::contains(const QString& key) const bool CustomData::containsValue(const QString& value) const { - return m_data.values().contains(value); + return asConst(m_data).values().contains(value); } void CustomData::set(const QString& key, const QString& value) diff --git a/src/core/EntryAttachments.cpp b/src/core/EntryAttachments.cpp index dfa59ec8c..49f5198d2 100644 --- a/src/core/EntryAttachments.cpp +++ b/src/core/EntryAttachments.cpp @@ -17,6 +17,8 @@ #include "EntryAttachments.h" +#include "core/Global.h" + #include #include @@ -37,7 +39,7 @@ bool EntryAttachments::hasKey(const QString& key) const QSet EntryAttachments::values() const { - return m_attachments.values().toSet(); + return asConst(m_attachments).values().toSet(); } QByteArray EntryAttachments::value(const QString& key) const diff --git a/src/core/EntryAttributes.cpp b/src/core/EntryAttributes.cpp index 5c836e1e8..3a696ae66 100644 --- a/src/core/EntryAttributes.cpp +++ b/src/core/EntryAttributes.cpp @@ -18,6 +18,8 @@ #include "EntryAttributes.h" +#include "core/Global.h" + const QString EntryAttributes::TitleKey = "Title"; const QString EntryAttributes::UserNameKey = "UserName"; const QString EntryAttributes::PasswordKey = "Password"; @@ -72,7 +74,7 @@ bool EntryAttributes::contains(const QString& key) const bool EntryAttributes::containsValue(const QString& value) const { - return m_attributes.values().contains(value); + return asConst(m_attributes).values().contains(value); } bool EntryAttributes::isProtected(const QString& key) const diff --git a/src/core/Merger.cpp b/src/core/Merger.cpp index cc57ae3b2..e4cf0f994 100644 --- a/src/core/Merger.cpp +++ b/src/core/Merger.cpp @@ -616,7 +616,8 @@ Merger::ChangeList Merger::mergeMetadata(const MergeContext& context) auto* sourceMetadata = context.m_sourceDb->metadata(); auto* targetMetadata = context.m_targetDb->metadata(); - for (QUuid customIconId : sourceMetadata->customIcons().keys()) { + const auto keys = sourceMetadata->customIcons().keys(); + for (QUuid customIconId : keys) { QImage customIcon = sourceMetadata->customIcon(customIconId); if (!targetMetadata->containsCustomIcon(customIconId)) { targetMetadata->addCustomIcon(customIconId, customIcon); diff --git a/src/format/KdbxXmlReader.cpp b/src/format/KdbxXmlReader.cpp index efef724d9..50c320118 100644 --- a/src/format/KdbxXmlReader.cpp +++ b/src/format/KdbxXmlReader.cpp @@ -124,8 +124,8 @@ void KdbxXmlReader::readDatabase(QIODevice* device, Database* db, KeePass2Random qWarning("KdbxXmlReader::readDatabase: found %d invalid entry reference(s)", m_tmpParent->children().size()); } - const QSet poolKeys = m_binaryPool.keys().toSet(); - const QSet entryKeys = m_binaryMap.keys().toSet(); + const QSet poolKeys = asConst(m_binaryPool).keys().toSet(); + const QSet entryKeys = asConst(m_binaryMap).keys().toSet(); const QSet unmappedKeys = entryKeys - poolKeys; const QSet unusedKeys = poolKeys - entryKeys;