Avoid creation of temporary containers

This commit is contained in:
Gianluca Recchia 2019-01-17 07:23:22 +01:00 committed by Jonathan White
parent 39b96c13e8
commit 2cf837801d
No known key found for this signature in database
GPG Key ID: 440FC65F2E0C6E01
6 changed files with 15 additions and 7 deletions

View File

@ -91,7 +91,8 @@ void Config::sync()
void Config::upgrade() 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 (m_settings->contains(setting)) {
if (!deprecationMap.value(setting).isEmpty()) { if (!deprecationMap.value(setting).isEmpty()) {
// Add entry with new name and old entry's value // Add entry with new name and old entry's value

View File

@ -17,6 +17,8 @@
#include "CustomData.h" #include "CustomData.h"
#include "core/Global.h"
CustomData::CustomData(QObject* parent) CustomData::CustomData(QObject* parent)
: QObject(parent) : QObject(parent)
{ {
@ -44,7 +46,7 @@ bool CustomData::contains(const QString& key) const
bool CustomData::containsValue(const QString& value) 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) void CustomData::set(const QString& key, const QString& value)

View File

@ -17,6 +17,8 @@
#include "EntryAttachments.h" #include "EntryAttachments.h"
#include "core/Global.h"
#include <QSet> #include <QSet>
#include <QStringList> #include <QStringList>
@ -37,7 +39,7 @@ bool EntryAttachments::hasKey(const QString& key) const
QSet<QByteArray> EntryAttachments::values() const QSet<QByteArray> EntryAttachments::values() const
{ {
return m_attachments.values().toSet(); return asConst(m_attachments).values().toSet();
} }
QByteArray EntryAttachments::value(const QString& key) const QByteArray EntryAttachments::value(const QString& key) const

View File

@ -18,6 +18,8 @@
#include "EntryAttributes.h" #include "EntryAttributes.h"
#include "core/Global.h"
const QString EntryAttributes::TitleKey = "Title"; const QString EntryAttributes::TitleKey = "Title";
const QString EntryAttributes::UserNameKey = "UserName"; const QString EntryAttributes::UserNameKey = "UserName";
const QString EntryAttributes::PasswordKey = "Password"; const QString EntryAttributes::PasswordKey = "Password";
@ -72,7 +74,7 @@ bool EntryAttributes::contains(const QString& key) const
bool EntryAttributes::containsValue(const QString& value) 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 bool EntryAttributes::isProtected(const QString& key) const

View File

@ -616,7 +616,8 @@ Merger::ChangeList Merger::mergeMetadata(const MergeContext& context)
auto* sourceMetadata = context.m_sourceDb->metadata(); auto* sourceMetadata = context.m_sourceDb->metadata();
auto* targetMetadata = context.m_targetDb->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); QImage customIcon = sourceMetadata->customIcon(customIconId);
if (!targetMetadata->containsCustomIcon(customIconId)) { if (!targetMetadata->containsCustomIcon(customIconId)) {
targetMetadata->addCustomIcon(customIconId, customIcon); targetMetadata->addCustomIcon(customIconId, customIcon);

View File

@ -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()); qWarning("KdbxXmlReader::readDatabase: found %d invalid entry reference(s)", m_tmpParent->children().size());
} }
const QSet<QString> poolKeys = m_binaryPool.keys().toSet(); const QSet<QString> poolKeys = asConst(m_binaryPool).keys().toSet();
const QSet<QString> entryKeys = m_binaryMap.keys().toSet(); const QSet<QString> entryKeys = asConst(m_binaryMap).keys().toSet();
const QSet<QString> unmappedKeys = entryKeys - poolKeys; const QSet<QString> unmappedKeys = entryKeys - poolKeys;
const QSet<QString> unusedKeys = poolKeys - entryKeys; const QSet<QString> unusedKeys = poolKeys - entryKeys;