Avoid copying QSharedPointers when not needed

This commit is contained in:
Gianluca Recchia 2019-01-17 06:39:53 +01:00 committed by Jonathan White
parent 6df9c6f9b2
commit 39b96c13e8
No known key found for this signature in database
GPG Key ID: 440FC65F2E0C6E01
18 changed files with 31 additions and 29 deletions

View File

@ -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,
@ -482,7 +482,7 @@ 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();
@ -549,7 +549,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) {
@ -770,7 +770,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) {
@ -955,7 +955,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()) {

View File

@ -54,10 +54,10 @@ public:
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[];
@ -106,7 +106,7 @@ private:
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);
@ -116,7 +116,7 @@ private:
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);

View File

@ -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,

View File

@ -26,7 +26,7 @@ public:
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,

View File

@ -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;
@ -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);

View File

@ -33,7 +33,7 @@ public:
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

View File

@ -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)) {
@ -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");

View File

@ -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:

View File

@ -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)
{

View File

@ -60,7 +60,7 @@ public:
IconStruct state();
void reset();
void load(const QUuid& currentUuid,
QSharedPointer<Database> database,
const QSharedPointer<Database>& database,
const IconStruct& iconStruct,
const QString& url = "");

View File

@ -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);

View File

@ -61,7 +61,7 @@ public:
~DatabaseSettingsDialog() override;
Q_DISABLE_COPY(DatabaseSettingsDialog);
void load(QSharedPointer<Database> db);
void load(const QSharedPointer<Database>& db);
void addSettingsPage(IDatabaseSettingsPage* page);
void showMasterKeySettings();

View File

@ -18,6 +18,8 @@
#include "DatabaseSettingsWidget.h"
#include "core/Database.h"
#include <utility>
#include <QTimer>
#include <QWidget>
@ -38,6 +40,6 @@ DatabaseSettingsWidget::~DatabaseSettingsWidget()
*/
void DatabaseSettingsWidget::load(QSharedPointer<Database> db)
{
m_db = db;
m_db = std::move(db);
initialize();
}

View File

@ -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;

View File

@ -55,7 +55,7 @@ public:
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);

View File

@ -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());
}

View File

@ -30,7 +30,7 @@ class GroupView : public QTreeView
public:
explicit GroupView(Database* db, QWidget* parent = nullptr);
void changeDatabase(QSharedPointer<Database> newDb);
void changeDatabase(const QSharedPointer<Database>& newDb);
void setModel(QAbstractItemModel* model) override;
Group* currentGroup();
void setCurrentGroup(Group* group);

View File

@ -38,7 +38,7 @@ class NewDatabaseWizardPage : public QWizardPage
public:
explicit NewDatabaseWizardPage(QWidget* parent = nullptr);
Q_DISABLE_COPY(NewDatabaseWizardPage);
Q_DISABLE_COPY(NewDatabaseWizardPage)
~NewDatabaseWizardPage() override;
void setPageWidget(DatabaseSettingsWidget* page);