Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/keepassxreboot/keepassxc.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/src/core
diff options
context:
space:
mode:
authorGianluca Recchia <gianluca.recchia97@gmail.com>2018-10-28 14:49:32 +0300
committerGianluca Recchia <gianluca.recchia97@gmail.com>2018-10-31 17:16:04 +0300
commitda9afd3f6fcb7b7c3c5c02112ffe49c1ee34ba43 (patch)
treef25517212eeb197b0d452b0b3ec40bd9279d653d /src/core
parenta67a574b89ae1e12de158d6fdc5b51fdec6f13f3 (diff)
Reduce number of unneeded copies
This patch aims at reducing the number of copies for obejcts that could be referenced rather than copied, because they're not modified during the computation.
Diffstat (limited to 'src/core')
-rw-r--r--src/core/CsvParser.cpp6
-rw-r--r--src/core/CsvParser.h4
-rw-r--r--src/core/Database.cpp12
-rw-r--r--src/core/Database.h12
-rw-r--r--src/core/EntrySearcher.cpp4
-rw-r--r--src/core/Group.cpp12
-rw-r--r--src/core/Group.h12
-rw-r--r--src/core/PasswordGenerator.cpp2
-rw-r--r--src/core/PasswordGenerator.h2
9 files changed, 33 insertions, 33 deletions
diff --git a/src/core/CsvParser.cpp b/src/core/CsvParser.cpp
index a66c919b2..e545d1db4 100644
--- a/src/core/CsvParser.cpp
+++ b/src/core/CsvParser.cpp
@@ -1,4 +1,4 @@
-/*
+/*
* Copyright (C) 2016 Enrico Mariotti <enricomariotti@yahoo.it>
* Copyright (C) 2017 KeePassXC Team <team@keepassxc.org>
*
@@ -327,7 +327,7 @@ bool CsvParser::isText(QChar c) const
return !((isCRLF(c)) || (isSeparator(c)));
}
-bool CsvParser::isEmptyRow(CsvRow row) const
+bool CsvParser::isEmptyRow(const CsvRow& row) const
{
CsvRow::const_iterator it = row.constBegin();
for (; it != row.constEnd(); ++it)
@@ -414,7 +414,7 @@ int CsvParser::getCsvRows() const
return m_table.size();
}
-void CsvParser::appendStatusMsg(QString s, bool isCritical)
+void CsvParser::appendStatusMsg(const QString& s, bool isCritical)
{
m_statusMsg += QObject::tr("%1: (row, col) %2,%3").arg(s, m_currRow, m_currCol).append("\n");
m_isGood = !isCritical;
diff --git a/src/core/CsvParser.h b/src/core/CsvParser.h
index 323023114..d90e8300a 100644
--- a/src/core/CsvParser.h
+++ b/src/core/CsvParser.h
@@ -83,7 +83,7 @@ private:
bool isCRLF(const QChar& c) const;
bool isSpace(const QChar& c) const;
bool isTab(const QChar& c) const;
- bool isEmptyRow(CsvRow row) const;
+ bool isEmptyRow(const CsvRow& row) const;
bool parseFile();
void parseRecord();
void parseField(CsvRow& row);
@@ -96,7 +96,7 @@ private:
void clear();
bool skipEndline();
void skipLine();
- void appendStatusMsg(QString s, bool isCritical = false);
+ void appendStatusMsg(const QString& s, bool isCritical = false);
};
#endif // CSVPARSER_H
diff --git a/src/core/Database.cpp b/src/core/Database.cpp
index 5116fd199..693b9c549 100644
--- a/src/core/Database.cpp
+++ b/src/core/Database.cpp
@@ -315,7 +315,7 @@ void Database::setCompressionAlgo(Database::CompressionAlgorithm algo)
* @param updateTransformSalt true to update the transform salt
* @return true on success
*/
-bool Database::setKey(QSharedPointer<const CompositeKey> key, bool updateChangedTime, bool updateTransformSalt)
+bool Database::setKey(const QSharedPointer<const CompositeKey>& key, bool updateChangedTime, bool updateTransformSalt)
{
if (!key) {
m_data.key.reset();
@@ -354,7 +354,7 @@ bool Database::hasKey() const
return m_data.hasKey;
}
-bool Database::verifyKey(QSharedPointer<CompositeKey> key) const
+bool Database::verifyKey(const QSharedPointer<CompositeKey>& key) const
{
Q_ASSERT(hasKey());
@@ -501,7 +501,7 @@ Database* Database::openDatabaseFile(const QString& fileName, QSharedPointer<con
return db;
}
-Database* Database::unlockFromStdin(QString databaseFilename, QString keyFilename, FILE* outputDescriptor, FILE* errorDescriptor)
+Database* Database::unlockFromStdin(const QString& databaseFilename, const QString& keyFilename, FILE* outputDescriptor, FILE* errorDescriptor)
{
auto compositeKey = QSharedPointer<CompositeKey>::create();
QTextStream out(outputDescriptor);
@@ -553,7 +553,7 @@ Database* Database::unlockFromStdin(QString databaseFilename, QString keyFilenam
* @param backup Backup the existing database file, if exists
* @return error string, if any
*/
-QString Database::saveToFile(QString filePath, bool atomic, bool backup)
+QString Database::saveToFile(const QString& filePath, bool atomic, bool backup)
{
QString error;
if (atomic) {
@@ -633,7 +633,7 @@ QString Database::writeDatabase(QIODevice* device)
* @param filePath Path to the file to backup
* @return
*/
-bool Database::backupDatabase(QString filePath)
+bool Database::backupDatabase(const QString& filePath)
{
QString backupFilePath = filePath;
auto re = QRegularExpression("\\.kdbx$|(?<!\\.kdbx)$", QRegularExpression::CaseInsensitiveOption);
@@ -652,7 +652,7 @@ void Database::setKdf(QSharedPointer<Kdf> kdf)
m_data.kdf = std::move(kdf);
}
-bool Database::changeKdf(QSharedPointer<Kdf> kdf)
+bool Database::changeKdf(const QSharedPointer<Kdf>& kdf)
{
kdf->randomizeSeed();
QByteArray transformedMasterKey;
diff --git a/src/core/Database.h b/src/core/Database.h
index 7108ded31..692444f4d 100644
--- a/src/core/Database.h
+++ b/src/core/Database.h
@@ -110,9 +110,9 @@ public:
void setCipher(const QUuid& cipher);
void setCompressionAlgo(Database::CompressionAlgorithm algo);
void setKdf(QSharedPointer<Kdf> kdf);
- bool setKey(QSharedPointer<const CompositeKey> key, bool updateChangedTime = true, bool updateTransformSalt = false);
+ bool setKey(const QSharedPointer<const CompositeKey>& key, bool updateChangedTime = true, bool updateTransformSalt = false);
bool hasKey() const;
- bool verifyKey(QSharedPointer<CompositeKey> key) const;
+ bool verifyKey(const QSharedPointer<CompositeKey>& key) const;
QVariantMap& publicCustomData();
const QVariantMap& publicCustomData() const;
void setPublicCustomData(const QVariantMap& customData);
@@ -121,17 +121,17 @@ public:
void emptyRecycleBin();
void setEmitModified(bool value);
void markAsModified();
- QString saveToFile(QString filePath, bool atomic = true, bool backup = false);
+ QString saveToFile(const QString& filePath, bool atomic = true, bool backup = false);
/**
* Returns a unique id that is only valid as long as the Database exists.
*/
const QUuid& uuid();
- bool changeKdf(QSharedPointer<Kdf> kdf);
+ bool changeKdf(const QSharedPointer<Kdf>& kdf);
static Database* databaseByUuid(const QUuid& uuid);
static Database* openDatabaseFile(const QString& fileName, QSharedPointer<const CompositeKey> key);
- static Database* unlockFromStdin(QString databaseFilename, QString keyFilename = {},
+ static Database* unlockFromStdin(const QString& databaseFilename, const QString& keyFilename = {},
FILE* outputDescriptor = stdout, FILE* errorDescriptor = stderr);
signals:
@@ -156,7 +156,7 @@ private:
void createRecycleBin();
QString writeDatabase(QIODevice* device);
- bool backupDatabase(QString filePath);
+ bool backupDatabase(const QString& filePath);
Metadata* const m_metadata;
Group* m_rootGroup;
diff --git a/src/core/EntrySearcher.cpp b/src/core/EntrySearcher.cpp
index 820646a98..3413f1cd0 100644
--- a/src/core/EntrySearcher.cpp
+++ b/src/core/EntrySearcher.cpp
@@ -34,12 +34,12 @@ EntrySearcher::searchEntries(const QString& searchTerm, const Group* group, Qt::
{
QList<Entry*> searchResult;
- const QList<Entry*> entryList = group->entries();
+ const QList<Entry*>& entryList = group->entries();
for (Entry* entry : entryList) {
searchResult.append(matchEntry(searchTerm, entry, caseSensitivity));
}
- const QList<Group*> children = group->children();
+ const QList<Group*>& children = group->children();
for (Group* childGroup : children) {
if (childGroup->searchingEnabled() != Group::Disable) {
if (matchGroup(searchTerm, childGroup, caseSensitivity)) {
diff --git a/src/core/Group.cpp b/src/core/Group.cpp
index 72f2490a0..4b1d11ab0 100644
--- a/src/core/Group.cpp
+++ b/src/core/Group.cpp
@@ -563,7 +563,7 @@ Entry* Group::findEntryByUuid(const QUuid& uuid) const
return nullptr;
}
-Entry* Group::findEntryByPath(QString entryPath)
+Entry* Group::findEntryByPath(const QString& entryPath)
{
if (entryPath.isEmpty()) {
return nullptr;
@@ -578,7 +578,7 @@ Entry* Group::findEntryByPath(QString entryPath)
return findEntryByPathRecursive(normalizedEntryPath, "/");
}
-Entry* Group::findEntryByPathRecursive(QString entryPath, QString basePath)
+Entry* Group::findEntryByPathRecursive(const QString& entryPath, const QString& basePath)
{
// Return the first entry that matches the full path OR if there is no leading
// slash, return the first entry title that matches
@@ -599,7 +599,7 @@ Entry* Group::findEntryByPathRecursive(QString entryPath, QString basePath)
return nullptr;
}
-Group* Group::findGroupByPath(QString groupPath)
+Group* Group::findGroupByPath(const QString& groupPath)
{
// normalize the groupPath by adding missing front and rear slashes. once.
QString normalizedGroupPath;
@@ -614,7 +614,7 @@ Group* Group::findGroupByPath(QString groupPath)
return findGroupByPathRecursive(normalizedGroupPath, "/");
}
-Group* Group::findGroupByPathRecursive(QString groupPath, QString basePath)
+Group* Group::findGroupByPathRecursive(const QString& groupPath, const QString& basePath)
{
// paths must be normalized
Q_ASSERT(groupPath.startsWith("/") && groupPath.endsWith("/"));
@@ -926,7 +926,7 @@ bool Group::resolveAutoTypeEnabled() const
}
}
-QStringList Group::locate(QString locateTerm, QString currentPath) const
+QStringList Group::locate(const QString& locateTerm, const QString& currentPath) const
{
// TODO: Replace with EntrySearcher
QStringList response;
@@ -950,7 +950,7 @@ QStringList Group::locate(QString locateTerm, QString currentPath) const
return response;
}
-Entry* Group::addEntryWithPath(QString entryPath)
+Entry* Group::addEntryWithPath(const QString& entryPath)
{
if (entryPath.isEmpty() || findEntryByPath(entryPath)) {
return nullptr;
diff --git a/src/core/Group.h b/src/core/Group.h
index 3a9332c8e..da6994d2a 100644
--- a/src/core/Group.h
+++ b/src/core/Group.h
@@ -115,11 +115,11 @@ public:
Group* findChildByName(const QString& name);
Entry* findEntryByUuid(const QUuid& uuid) const;
- Entry* findEntryByPath(QString entryPath);
+ Entry* findEntryByPath(const QString& entryPath);
Group* findGroupByUuid(const QUuid& uuid);
- Group* findGroupByPath(QString groupPath);
- QStringList locate(QString locateTerm, QString currentPath = {"/"}) const;
- Entry* addEntryWithPath(QString entryPath);
+ Group* findGroupByPath(const QString& groupPath);
+ QStringList locate(const QString& locateTerm, const QString& currentPath = {"/"}) const;
+ Entry* addEntryWithPath(const QString& entryPath);
void setUuid(const QUuid& uuid);
void setName(const QString& name);
void setNotes(const QString& notes);
@@ -190,8 +190,8 @@ private:
void cleanupParent();
void recCreateDelObjects();
- Entry* findEntryByPathRecursive(QString entryPath, QString basePath);
- Group* findGroupByPathRecursive(QString groupPath, QString basePath);
+ Entry* findEntryByPathRecursive(const QString& entryPath, const QString& basePath);
+ Group* findGroupByPathRecursive(const QString& groupPath, const QString& basePath);
QPointer<Database> m_db;
QUuid m_uuid;
diff --git a/src/core/PasswordGenerator.cpp b/src/core/PasswordGenerator.cpp
index 3dbcdaad8..124b99896 100644
--- a/src/core/PasswordGenerator.cpp
+++ b/src/core/PasswordGenerator.cpp
@@ -31,7 +31,7 @@ PasswordGenerator::PasswordGenerator()
{
}
-double PasswordGenerator::calculateEntropy(QString password)
+double PasswordGenerator::calculateEntropy(const QString& password)
{
return ZxcvbnMatch(password.toLatin1(), 0, 0);
}
diff --git a/src/core/PasswordGenerator.h b/src/core/PasswordGenerator.h
index cb6402d0f..7bfdddd69 100644
--- a/src/core/PasswordGenerator.h
+++ b/src/core/PasswordGenerator.h
@@ -57,7 +57,7 @@ public:
public:
PasswordGenerator();
- double calculateEntropy(QString password);
+ double calculateEntropy(const QString& password);
void setLength(int length);
void setCharClasses(const CharClasses& classes);
void setFlags(const GeneratorFlags& flags);