Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Performance fixes #2610

Merged
merged 7 commits into from
Jan 30, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions src/browser/BrowserService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ void BrowserService::addEntry(const QString& id,
const QString& realm,
const QString& group,
const QString& groupUuid,
QSharedPointer<Database> selectedDb)
const QSharedPointer<Database>& selectedDb)
{
if (thread() != QThread::currentThread()) {
QMetaObject::invokeMethod(this,
Expand Down Expand Up @@ -482,7 +482,8 @@ void BrowserService::updateEntry(const QString& id,
}
}

QList<Entry*> BrowserService::searchEntries(QSharedPointer<Database> db, const QString& hostname, const QString& url)
QList<Entry*>
BrowserService::searchEntries(const QSharedPointer<Database>& db, const QString& hostname, const QString& url)
{
QList<Entry*> entries;
auto* rootGroup = db->rootGroup();
Expand Down Expand Up @@ -549,7 +550,7 @@ QList<Entry*> BrowserService::searchEntries(const QString& url, const StringPair
return entries;
}

void BrowserService::convertAttributesToCustomData(QSharedPointer<Database> currentDb)
void BrowserService::convertAttributesToCustomData(const QSharedPointer<Database>& currentDb)
{
auto db = currentDb ? currentDb : getDatabase();
if (!db) {
Expand Down Expand Up @@ -770,7 +771,7 @@ BrowserService::checkAccess(const Entry* entry, const QString& host, const QStri
return Unknown;
}

Group* BrowserService::findCreateAddEntryGroup(QSharedPointer<Database> selectedDb)
Group* BrowserService::findCreateAddEntryGroup(const QSharedPointer<Database>& selectedDb)
{
auto db = selectedDb ? selectedDb : getDatabase();
if (!db) {
Expand Down Expand Up @@ -955,7 +956,7 @@ bool BrowserService::moveSettingsToCustomData(Entry* entry, const QString& name)
return false;
}

int BrowserService::moveKeysToCustomData(Entry* entry, QSharedPointer<Database> db) const
int BrowserService::moveKeysToCustomData(Entry* entry, const QSharedPointer<Database>& db) const
{
int keyCounter = 0;
for (const auto& key : entry->attributes()->keys()) {
Expand Down
10 changes: 5 additions & 5 deletions src/browser/BrowserService.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,10 @@ class BrowserService : public QObject
const QString& realm,
const QString& group,
const QString& groupUuid,
QSharedPointer<Database> selectedDb = {});
QList<Entry*> searchEntries(QSharedPointer<Database> db, const QString& hostname, const QString& url);
const QSharedPointer<Database>& selectedDb = {});
QList<Entry*> searchEntries(const QSharedPointer<Database>& db, const QString& hostname, const QString& url);
QList<Entry*> searchEntries(const QString& url, const StringPairList& keyList);
void convertAttributesToCustomData(QSharedPointer<Database> currentDb = {});
void convertAttributesToCustomData(const QSharedPointer<Database>& currentDb = {});

public:
static const char KEEPASSXCBROWSER_NAME[];
Expand Down Expand Up @@ -106,7 +106,7 @@ public slots:
const QString& realm);
QJsonObject prepareEntry(const Entry* entry);
Access checkAccess(const Entry* entry, const QString& host, const QString& submitHost, const QString& realm);
Group* findCreateAddEntryGroup(QSharedPointer<Database> selectedDb = {});
Group* findCreateAddEntryGroup(const QSharedPointer<Database>& selectedDb = {});
int
sortPriority(const Entry* entry, const QString& host, const QString& submitUrl, const QString& baseSubmitUrl) const;
bool matchUrlScheme(const QString& url);
Expand All @@ -116,7 +116,7 @@ public slots:
QSharedPointer<Database> selectedDatabase();
QJsonArray addChildrenToGroup(Group* group);
bool moveSettingsToCustomData(Entry* entry, const QString& name) const;
int moveKeysToCustomData(Entry* entry, QSharedPointer<Database> db) const;
int moveKeysToCustomData(Entry* entry, const QSharedPointer<Database>& db) const;
bool checkLegacySettings();
void hideWindow() const;
void raiseWindow(const bool force = false);
Expand Down
2 changes: 1 addition & 1 deletion src/cli/Clip.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ int Clip::execute(const QStringList& arguments)
return clipEntry(db, args.at(1), args.value(2), parser.isSet(totp), parser.isSet(Command::QuietOption));
}

int Clip::clipEntry(QSharedPointer<Database> database,
int Clip::clipEntry(const QSharedPointer<Database>& database,
const QString& entryPath,
const QString& timeout,
bool clipTotp,
Expand Down
2 changes: 1 addition & 1 deletion src/cli/Clip.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class Clip : public Command
Clip();
~Clip();
int execute(const QStringList& arguments) override;
int clipEntry(QSharedPointer<Database> database,
int clipEntry(const QSharedPointer<Database>& database,
const QString& entryPath,
const QString& timeout,
bool clipTotp,
Expand Down
4 changes: 2 additions & 2 deletions src/cli/Create.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ int Create::execute(const QStringList& arguments)
return EXIT_FAILURE;
}

QString databaseFilename = args.at(0);
const QString& databaseFilename = args.at(0);
if (QFileInfo::exists(databaseFilename)) {
err << QObject::tr("File %1 already exists.").arg(databaseFilename) << endl;
return EXIT_FAILURE;
Expand Down Expand Up @@ -150,7 +150,7 @@ QSharedPointer<PasswordKey> Create::getPasswordFromStdin()
* @param fileKey Resulting fileKey
* @return true if the key file was loaded succesfully
*/
bool Create::loadFileKey(QString path, QSharedPointer<FileKey>& fileKey)
bool Create::loadFileKey(const QString& path, QSharedPointer<FileKey>& fileKey)
{
QTextStream err(Utils::STDERR, QIODevice::WriteOnly);

Expand Down
2 changes: 1 addition & 1 deletion src/cli/Create.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class Create : public Command
private:
QSharedPointer<PasswordKey> getPasswordFromStdin();
QSharedPointer<FileKey> getFileKeyFromStdin();
bool loadFileKey(QString path, QSharedPointer<FileKey>& fileKey);
bool loadFileKey(const QString& path, QSharedPointer<FileKey>& fileKey);
};

#endif // KEEPASSXC_CREATE_H
12 changes: 6 additions & 6 deletions src/cli/Utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,13 +135,13 @@ namespace Utils

auto db = QSharedPointer<Database>::create();
QString error;
if (db->open(databaseFilename, compositeKey, &error, false)) {
return db;
}else {
err << error << endl;
return {};
if (db->open(databaseFilename, compositeKey, &error, false)) {
return db;
} else {
err << error << endl;
return {};
}
}
}

/**
* Read a user password from STDIN or return a password previously
Expand Down
11 changes: 6 additions & 5 deletions src/core/Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@
*/
static const QMap<QString, QString> deprecationMap = {
// >2.3.4
{"security/hidepassworddetails", "security/HidePasswordPreviewPanel"},
{QStringLiteral("security/hidepassworddetails"), QStringLiteral("security/HidePasswordPreviewPanel")},
// >2.3.4
{"GUI/HideDetailsView", "GUI/HidePreviewPanel"},
{QStringLiteral("GUI/HideDetailsView"), QStringLiteral("GUI/HidePreviewPanel")},
// >2.3.4
{"GUI/DetailSplitterState", "GUI/PreviewSplitterState"},
{QStringLiteral("GUI/DetailSplitterState"), QStringLiteral("GUI/PreviewSplitterState")},
// >2.3.4
{"security/IconDownloadFallbackToGoogle", "security/IconDownloadFallback"},
{QStringLiteral("security/IconDownloadFallbackToGoogle"), QStringLiteral("security/IconDownloadFallback")},
};

Config* Config::m_instance(nullptr);
Expand Down Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion src/core/CustomData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

#include "CustomData.h"

#include "core/Global.h"

CustomData::CustomData(QObject* parent)
: QObject(parent)
{
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 3 additions & 1 deletion src/core/EntryAttachments.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

#include "EntryAttachments.h"

#include "core/Global.h"

#include <QSet>
#include <QStringList>

Expand All @@ -37,7 +39,7 @@ bool EntryAttachments::hasKey(const QString& key) const

QSet<QByteArray> EntryAttachments::values() const
{
return m_attachments.values().toSet();
return asConst(m_attachments).values().toSet();
}

QByteArray EntryAttachments::value(const QString& key) const
Expand Down
4 changes: 3 additions & 1 deletion src/core/EntryAttributes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion src/core/Merger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions src/format/CsvExporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
#include "core/Database.h"
#include "core/Group.h"

bool CsvExporter::exportDatabase(const QString& filename, QSharedPointer<const Database> db)
bool CsvExporter::exportDatabase(const QString& filename, const QSharedPointer<const Database>& db)
{
QFile file(filename);
if (!file.open(QIODevice::WriteOnly | QIODevice::Truncate)) {
Expand All @@ -33,7 +33,7 @@ bool CsvExporter::exportDatabase(const QString& filename, QSharedPointer<const D
return exportDatabase(&file, db);
}

bool CsvExporter::exportDatabase(QIODevice* device, QSharedPointer<const Database> db)
bool CsvExporter::exportDatabase(QIODevice* device, const QSharedPointer<const Database>& db)
{
QString header;
addColumn(header, "Group");
Expand Down
4 changes: 2 additions & 2 deletions src/format/CsvExporter.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ class QIODevice;
class CsvExporter
{
public:
bool exportDatabase(const QString& filename, QSharedPointer<const Database> db);
bool exportDatabase(QIODevice* device, QSharedPointer<const Database> db);
bool exportDatabase(const QString& filename, const QSharedPointer<const Database>& db);
bool exportDatabase(QIODevice* device, const QSharedPointer<const Database>& db);
QString errorString() const;

private:
Expand Down
4 changes: 2 additions & 2 deletions src/format/KdbxXmlReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<QString> poolKeys = m_binaryPool.keys().toSet();
const QSet<QString> entryKeys = m_binaryMap.keys().toSet();
const QSet<QString> poolKeys = asConst(m_binaryPool).keys().toSet();
const QSet<QString> entryKeys = asConst(m_binaryMap).keys().toSet();
const QSet<QString> unmappedKeys = entryKeys - poolKeys;
const QSet<QString> unusedKeys = poolKeys - entryKeys;

Expand Down
2 changes: 1 addition & 1 deletion src/gui/DatabaseWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1532,7 +1532,7 @@ bool DatabaseWidget::saveAs()
{
while (true) {
QString oldFilePath = m_db->filePath();
if (!QFileInfo(oldFilePath).exists()) {
if (!QFileInfo::exists(oldFilePath)) {
oldFilePath = QDir::toNativeSeparators(config()->get("LastDir", QDir::homePath()).toString() + "/"
+ tr("Passwords").append(".kdbx"));
}
Expand Down
3 changes: 1 addition & 2 deletions src/gui/EditWidgetIcons.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ void EditWidgetIcons::reset()
}

void EditWidgetIcons::load(const QUuid& currentUuid,
QSharedPointer<Database> database,
const QSharedPointer<Database>& database,
const IconStruct& iconStruct,
const QString& url)
{
Expand Down Expand Up @@ -229,7 +229,6 @@ void EditWidgetIcons::fetchFinished()
QImage image;
bool fallbackEnabled = config()->get("security/IconDownloadFallback", false).toBool();
bool error = (m_reply->error() != QNetworkReply::NoError);
QUrl url = m_reply->url();
QUrl redirectTarget = getRedirectTarget(m_reply);

m_reply->deleteLater();
Expand Down
2 changes: 1 addition & 1 deletion src/gui/EditWidgetIcons.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class EditWidgetIcons : public QWidget
IconStruct state();
void reset();
void load(const QUuid& currentUuid,
QSharedPointer<Database> database,
const QSharedPointer<Database>& database,
const IconStruct& iconStruct,
const QString& url = "");

Expand Down
4 changes: 2 additions & 2 deletions src/gui/MessageBox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@

MessageBox::Button MessageBox::m_nextAnswer(MessageBox::NoButton);

QMap<QAbstractButton*, MessageBox::Button> MessageBox::m_addedButtonLookup =
QMap<QAbstractButton*, MessageBox::Button>();
QHash<QAbstractButton*, MessageBox::Button> MessageBox::m_addedButtonLookup =
QHash<QAbstractButton*, MessageBox::Button>();

QMap<MessageBox::Button, std::pair<QString, QMessageBox::ButtonRole>> MessageBox::m_buttonDefs =
QMap<MessageBox::Button, std::pair<QString, QMessageBox::ButtonRole>>();
Expand Down
3 changes: 2 additions & 1 deletion src/gui/MessageBox.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#ifndef KEEPASSX_MESSAGEBOX_H
#define KEEPASSX_MESSAGEBOX_H

#include <QHash>
#include <QMap>
#include <QMessageBox>
#include <QPushButton>
Expand Down Expand Up @@ -102,7 +103,7 @@ class MessageBox

private:
static Button m_nextAnswer;
static QMap<QAbstractButton*, Button> m_addedButtonLookup;
static QHash<QAbstractButton*, Button> m_addedButtonLookup;
static QMap<Button, std::pair<QString, QMessageBox::ButtonRole>> m_buttonDefs;

static Button messageBox(QWidget* parent,
Expand Down
2 changes: 1 addition & 1 deletion src/gui/dbsettings/DatabaseSettingsDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ DatabaseSettingsDialog::~DatabaseSettingsDialog()
{
}

void DatabaseSettingsDialog::load(QSharedPointer<Database> db)
void DatabaseSettingsDialog::load(const QSharedPointer<Database>& db)
{
m_ui->categoryList->setCurrentCategory(0);
m_generalWidget->load(db);
Expand Down
2 changes: 1 addition & 1 deletion src/gui/dbsettings/DatabaseSettingsDialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class DatabaseSettingsDialog : public DialogyWidget
~DatabaseSettingsDialog() override;
Q_DISABLE_COPY(DatabaseSettingsDialog);

void load(QSharedPointer<Database> db);
void load(const QSharedPointer<Database>& db);
void addSettingsPage(IDatabaseSettingsPage* page);
void showMasterKeySettings();

Expand Down
4 changes: 3 additions & 1 deletion src/gui/dbsettings/DatabaseSettingsWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
#include "DatabaseSettingsWidget.h"
#include "core/Database.h"

#include <utility>

#include <QTimer>
#include <QWidget>

Expand All @@ -38,6 +40,6 @@ DatabaseSettingsWidget::~DatabaseSettingsWidget()
*/
void DatabaseSettingsWidget::load(QSharedPointer<Database> db)
{
m_db = db;
m_db = std::move(db);
initialize();
}
2 changes: 1 addition & 1 deletion src/gui/group/EditGroupWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ EditGroupWidget::~EditGroupWidget()
{
}

void EditGroupWidget::loadGroup(Group* group, bool create, QSharedPointer<Database> database)
void EditGroupWidget::loadGroup(Group* group, bool create, const QSharedPointer<Database>& database)
{
m_group = group;
m_db = database;
Expand Down
2 changes: 1 addition & 1 deletion src/gui/group/EditGroupWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class EditGroupWidget : public EditWidget
explicit EditGroupWidget(QWidget* parent = nullptr);
~EditGroupWidget();

void loadGroup(Group* group, bool create, QSharedPointer<Database> database);
void loadGroup(Group* group, bool create, const QSharedPointer<Database>& database);
void clear();

void addEditPage(IEditGroupPage* page);
Expand Down
2 changes: 1 addition & 1 deletion src/gui/group/GroupView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ GroupView::GroupView(Database* db, QWidget* parent)
setDefaultDropAction(Qt::MoveAction);
}

void GroupView::changeDatabase(QSharedPointer<Database> newDb)
void GroupView::changeDatabase(const QSharedPointer<Database>& newDb)
{
m_model->changeDatabase(newDb.data());
}
Expand Down
Loading