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.
This commit is contained in:
Gianluca Recchia 2018-10-28 12:49:32 +01:00
parent a67a574b89
commit da9afd3f6f
No known key found for this signature in database
GPG Key ID: 3C2B4128D9A1F218
40 changed files with 90 additions and 90 deletions

View File

@ -468,7 +468,7 @@ QJsonObject BrowserAction::decryptMessage(const QString& message, const QString&
return getErrorReply(action, ERROR_KEEPASS_CANNOT_DECRYPT_MESSAGE);
}
QString BrowserAction::encrypt(const QString plaintext, const QString nonce)
QString BrowserAction::encrypt(const QString& plaintext, const QString& nonce)
{
QMutexLocker locker(&m_mutex);
const QByteArray ma = plaintext.toUtf8();
@ -496,7 +496,7 @@ QString BrowserAction::encrypt(const QString plaintext, const QString nonce)
return QString();
}
QByteArray BrowserAction::decrypt(const QString encrypted, const QString nonce)
QByteArray BrowserAction::decrypt(const QString& encrypted, const QString& nonce)
{
QMutexLocker locker(&m_mutex);
const QByteArray ma = base64Decode(encrypted);
@ -546,14 +546,14 @@ QJsonObject BrowserAction::getJsonObject(const uchar* pArray, const uint len) co
return doc.object();
}
QJsonObject BrowserAction::getJsonObject(const QByteArray ba) const
QJsonObject BrowserAction::getJsonObject(const QByteArray& ba) const
{
QJsonParseError err;
QJsonDocument doc(QJsonDocument::fromJson(ba, &err));
return doc.object();
}
QByteArray BrowserAction::base64Decode(const QString str)
QByteArray BrowserAction::base64Decode(const QString& str)
{
return QByteArray::fromBase64(str.toUtf8());
}

View File

@ -73,14 +73,14 @@ private:
QString encryptMessage(const QJsonObject& message, const QString& nonce);
QJsonObject decryptMessage(const QString& message, const QString& nonce, const QString& action = QString());
QString encrypt(const QString plaintext, const QString nonce);
QByteArray decrypt(const QString encrypted, const QString nonce);
QString encrypt(const QString& plaintext, const QString& nonce);
QByteArray decrypt(const QString& encrypted, const QString& nonce);
QString getBase64FromKey(const uchar* array, const uint len);
QByteArray getQByteArray(const uchar* array, const uint len) const;
QJsonObject getJsonObject(const uchar* pArray, const uint len) const;
QJsonObject getJsonObject(const QByteArray ba) const;
QByteArray base64Decode(const QString str);
QJsonObject getJsonObject(const QByteArray& ba) const;
QByteArray base64Decode(const QString& str);
QString incrementNonce(const QString& nonce);
private:

View File

@ -169,7 +169,7 @@ QString BrowserSettings::customProxyLocation()
return config()->get("Browser/CustomProxyLocation", "").toString();
}
void BrowserSettings::setCustomProxyLocation(QString location)
void BrowserSettings::setCustomProxyLocation(const QString& location)
{
config()->set("Browser/CustomProxyLocation", location);
}
@ -364,7 +364,7 @@ QString BrowserSettings::passwordExcludedChars()
return config()->get("generator/ExcludedChars", PasswordGenerator::DefaultExcludedChars).toString();
}
void BrowserSettings::setPasswordExcludedChars(QString chars)
void BrowserSettings::setPasswordExcludedChars(const QString& chars)
{
config()->set("generator/ExcludedChars", chars);
}
@ -384,7 +384,7 @@ QString BrowserSettings::passPhraseWordSeparator()
return config()->get("generator/WordSeparator", PassphraseGenerator::DefaultSeparator).toString();
}
void BrowserSettings::setPassPhraseWordSeparator(QString separator)
void BrowserSettings::setPassPhraseWordSeparator(const QString& separator)
{
config()->set("generator/WordSeparator", separator);
}
@ -496,7 +496,7 @@ QString BrowserSettings::generatePassword()
}
}
void BrowserSettings::updateBinaryPaths(QString customProxyLocation)
void BrowserSettings::updateBinaryPaths(const QString& customProxyLocation)
{
bool isProxy = supportBrowserProxy();
m_hostInstaller.updateBinaryPaths(isProxy, customProxyLocation);

View File

@ -59,7 +59,7 @@ public:
bool useCustomProxy();
void setUseCustomProxy(bool enabled);
QString customProxyLocation();
void setCustomProxyLocation(QString location);
void setCustomProxyLocation(const QString& location);
bool updateBinaryPath();
void setUpdateBinaryPath(bool enabled);
bool chromeSupport();
@ -98,11 +98,11 @@ public:
bool advancedMode();
void setAdvancedMode(bool advancedMode);
QString passwordExcludedChars();
void setPasswordExcludedChars(QString chars);
void setPasswordExcludedChars(const QString& chars);
int passPhraseWordCount();
void setPassPhraseWordCount(int wordCount);
QString passPhraseWordSeparator();
void setPassPhraseWordSeparator(QString separator);
void setPassPhraseWordSeparator(const QString& separator);
int generatorType();
void setGeneratorType(int type);
bool passwordEveryGroup();
@ -114,7 +114,7 @@ public:
PasswordGenerator::CharClasses passwordCharClasses();
PasswordGenerator::GeneratorFlags passwordGeneratorFlags();
QString generatePassword();
void updateBinaryPaths(QString customProxyLocation = QString());
void updateBinaryPaths(const QString& customProxyLocation = QString());
bool checkIfProxyExists(QString& path);
private:

View File

@ -71,7 +71,7 @@ int Clip::execute(const QStringList& arguments)
return clipEntry(db, args.at(1), args.value(2));
}
int Clip::clipEntry(Database* database, QString entryPath, QString timeout)
int Clip::clipEntry(Database* database, const QString& entryPath, const QString& timeout)
{
TextStream err(Utils::STDERR);

View File

@ -26,7 +26,7 @@ public:
Clip();
~Clip();
int execute(const QStringList& arguments);
int clipEntry(Database* database, QString entryPath, QString timeout);
int clipEntry(Database* database, const QString& entryPath, const QString& timeout);
};
#endif // KEEPASSXC_CLIP_H

View File

@ -71,7 +71,7 @@ void populateCommands()
}
}
Command* Command::getCommand(QString commandName)
Command* Command::getCommand(const QString& commandName)
{
populateCommands();
if (commands.contains(commandName)) {

View File

@ -35,7 +35,7 @@ public:
QString getDescriptionLine();
static QList<Command*> getCommands();
static Command* getCommand(QString commandName);
static Command* getCommand(const QString& commandName);
};
#endif // KEEPASSXC_COMMAND_H

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -31,7 +31,7 @@ PasswordGenerator::PasswordGenerator()
{
}
double PasswordGenerator::calculateEntropy(QString password)
double PasswordGenerator::calculateEntropy(const QString& password)
{
return ZxcvbnMatch(password.toLatin1(), 0, 0);
}

View File

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

View File

@ -64,7 +64,7 @@ bool CsvExporter::writeGroup(QIODevice* device, const Group* group, QString grou
}
groupPath.append(group->name());
const QList<Entry*> entryList = group->entries();
const QList<Entry*>& entryList = group->entries();
for (const Entry* entry : entryList) {
QString line;
@ -83,7 +83,7 @@ bool CsvExporter::writeGroup(QIODevice* device, const Group* group, QString grou
}
}
const QList<Group*> children = group->children();
const QList<Group*>& children = group->children();
for (const Group* child : children) {
if (!writeGroup(device, child, groupPath)) {
return false;

View File

@ -59,7 +59,7 @@ const QList<QPair<QUuid, QString>> KeePass2::KDFS{
qMakePair(KeePass2::KDF_AES_KDBX3, QObject::tr("AES-KDF (KDBX 3.1)"))
};
QByteArray KeePass2::hmacKey(QByteArray masterSeed, QByteArray transformedMasterKey)
QByteArray KeePass2::hmacKey(const QByteArray& masterSeed, const QByteArray& transformedMasterKey)
{
CryptoHash hmacKeyHash(CryptoHash::Sha512);
hmacKeyHash.addData(masterSeed);
@ -98,7 +98,7 @@ QSharedPointer<Kdf> KeePass2::kdfFromParameters(const QVariantMap& p)
return kdf;
}
QVariantMap KeePass2::kdfToParameters(QSharedPointer<Kdf> kdf)
QVariantMap KeePass2::kdfToParameters(const QSharedPointer<Kdf>& kdf)
{
return kdf->writeParameters();
}

View File

@ -126,9 +126,9 @@ extern const QList<QPair<QUuid, QString>> KDFS;
ByteArray = 0x42
};
QByteArray hmacKey(QByteArray masterSeed, QByteArray transformedMasterKey);
QByteArray hmacKey(const QByteArray& masterSeed, const QByteArray& transformedMasterKey);
QSharedPointer<Kdf> kdfFromParameters(const QVariantMap& p);
QVariantMap kdfToParameters(QSharedPointer<Kdf> kdf);
QVariantMap kdfToParameters(const QSharedPointer<Kdf>& kdf);
QSharedPointer<Kdf> uuidToKdf(const QUuid& uuid);
ProtectedStreamAlgo idToProtectedStreamAlgo(quint32 id);

View File

@ -176,7 +176,7 @@ namespace {
// Try to get the 2nd level domain of the host part of a QUrl. For example,
// "foo.bar.example.com" would become "example.com", and "foo.bar.example.co.uk"
// would become "example.co.uk".
QString getSecondLevelDomain(QUrl url)
QString getSecondLevelDomain(const QUrl& url)
{
QString fqdn = url.host();
fqdn.truncate(fqdn.length() - url.topLevelDomain().length());
@ -185,7 +185,7 @@ namespace {
return newdom;
}
QUrl convertVariantToUrl(QVariant var)
QUrl convertVariantToUrl(const QVariant& var)
{
QUrl url;
if (var.canConvert<QUrl>())

View File

@ -178,7 +178,7 @@ FileDialog::FileDialog()
{
}
void FileDialog::saveLastDir(QString dir)
void FileDialog::saveLastDir(const QString& dir)
{
if (!dir.isEmpty() && !m_forgetLastDir) {
config()->set("LastDir", QFileInfo(dir).absolutePath());

View File

@ -65,7 +65,7 @@ private:
QString m_nextDirName;
bool m_forgetLastDir = false;
void saveLastDir(QString);
void saveLastDir(const QString&);
static FileDialog* m_instance;

View File

@ -673,7 +673,7 @@ void MainWindow::switchToOpenDatabase()
switchToDatabases();
}
void MainWindow::switchToDatabaseFile(QString file)
void MainWindow::switchToDatabaseFile(const QString& file)
{
m_ui->tabWidget->openDatabase(file);
switchToDatabases();

View File

@ -90,7 +90,7 @@ private slots:
void switchToPasswordGen(bool enabled);
void switchToNewDatabase();
void switchToOpenDatabase();
void switchToDatabaseFile(QString file);
void switchToDatabaseFile(const QString& file);
void switchToKeePass1Database();
void switchToCsvImport();
void closePasswordGen();

View File

@ -98,7 +98,7 @@ void PasswordEdit::updateStylesheet()
setStyleSheet(stylesheet);
}
void PasswordEdit::autocompletePassword(QString password)
void PasswordEdit::autocompletePassword(const QString& password)
{
if (config()->get("security/passwordsrepeat").toBool() && echoMode() == QLineEdit::Normal) {
setText(password);

View File

@ -41,7 +41,7 @@ signals:
private slots:
void updateStylesheet();
void autocompletePassword(QString password);
void autocompletePassword(const QString& password);
private:
bool passwordsEqual() const;

View File

@ -315,7 +315,7 @@ void CsvImportWidget::setRootGroup()
m_db->rootGroup()->setName("Root");
}
Group* CsvImportWidget::splitGroups(QString label)
Group* CsvImportWidget::splitGroups(const QString& label)
{
// extract group names from nested path provided in "label"
Group* current = m_db->rootGroup();
@ -345,7 +345,7 @@ Group* CsvImportWidget::splitGroups(QString label)
return current;
}
Group* CsvImportWidget::hasChildren(Group* current, QString groupName)
Group* CsvImportWidget::hasChildren(Group* current, const QString& groupName)
{
// returns the group whose name is "groupName" and is child of "current" group
for (Group* group : current->children()) {

View File

@ -68,8 +68,8 @@ private:
QStringList m_fieldSeparatorList;
void configParser();
void updateTableview();
Group* splitGroups(QString label);
Group* hasChildren(Group* current, QString groupName);
Group* splitGroups(const QString& label);
Group* hasChildren(Group* current, const QString& groupName);
QString formatStatusText() const;
};

View File

@ -37,7 +37,7 @@ AutoTypeMatch AutoTypeMatchModel::matchFromIndex(const QModelIndex& index) const
return m_matches.at(index.row());
}
QModelIndex AutoTypeMatchModel::indexFromMatch(AutoTypeMatch match) const
QModelIndex AutoTypeMatchModel::indexFromMatch(const AutoTypeMatch& match) const
{
int row = m_matches.indexOf(match);
Q_ASSERT(row != -1);

View File

@ -41,7 +41,7 @@ public:
explicit AutoTypeMatchModel(QObject* parent = nullptr);
AutoTypeMatch matchFromIndex(const QModelIndex& index) const;
QModelIndex indexFromMatch(AutoTypeMatch match) const;
QModelIndex indexFromMatch(const AutoTypeMatch& match) const;
int rowCount(const QModelIndex& parent = QModelIndex()) const override;
int columnCount(const QModelIndex& parent = QModelIndex()) const override;

View File

@ -98,7 +98,7 @@ AutoTypeMatch AutoTypeMatchView::currentMatch()
return AutoTypeMatch();
}
void AutoTypeMatchView::setCurrentMatch(AutoTypeMatch match)
void AutoTypeMatchView::setCurrentMatch(const AutoTypeMatch& match)
{
selectionModel()->setCurrentIndex(m_sortModel->mapFromSource(m_model->indexFromMatch(match)),
QItemSelectionModel::ClearAndSelect | QItemSelectionModel::Rows);

View File

@ -34,7 +34,7 @@ class AutoTypeMatchView : public QTreeView
public:
explicit AutoTypeMatchView(QWidget* parent = nullptr);
AutoTypeMatch currentMatch();
void setCurrentMatch(AutoTypeMatch match);
void setCurrentMatch(const AutoTypeMatch& match);
AutoTypeMatch matchFromIndex(const QModelIndex& index);
void setMatchList(const QList<AutoTypeMatch>& matches);
void setFirstMatchActive();

View File

@ -54,7 +54,7 @@ QVariant EntryHistoryModel::data(const QModelIndex& index, int role) const
if (role == Qt::DisplayRole || role == Qt::UserRole) {
Entry* entry = entryFromIndex(index);
TimeInfo timeInfo = entry->timeInfo();
const TimeInfo& timeInfo = entry->timeInfo();
QDateTime lastModificationLocalTime = timeInfo.lastModificationTime().toLocalTime();
switch (index.column()) {
case 0:

View File

@ -153,7 +153,7 @@ bool CompositeKey::challenge(const QByteArray& seed, QByteArray& result) const
*
* @param key the key
*/
void CompositeKey::addKey(QSharedPointer<Key> key)
void CompositeKey::addKey(const QSharedPointer<Key>& key)
{
m_keys.append(key);
}
@ -173,7 +173,7 @@ const QList<QSharedPointer<Key>>& CompositeKey::keys() const
*
* @param key the key
*/
void CompositeKey::addChallengeResponseKey(QSharedPointer<ChallengeResponseKey> key)
void CompositeKey::addChallengeResponseKey(const QSharedPointer<ChallengeResponseKey>& key)
{
m_challengeResponseKeys.append(key);
}

View File

@ -42,10 +42,10 @@ public:
Q_REQUIRED_RESULT bool transform(const Kdf& kdf, QByteArray& result) const;
bool challenge(const QByteArray& seed, QByteArray& result) const;
void addKey(QSharedPointer<Key> key);
void addKey(const QSharedPointer<Key>& key);
const QList<QSharedPointer<Key>>& keys() const;
void addChallengeResponseKey(QSharedPointer<ChallengeResponseKey> key);\
void addChallengeResponseKey(const QSharedPointer<ChallengeResponseKey>& key);\
const QList<QSharedPointer<ChallengeResponseKey>>& challengeResponseKeys() const;
private:

View File

@ -245,7 +245,7 @@ QByteArray HmacBlockStream::getCurrentHmacKey() const
return getHmacKey(m_blockIndex, m_key);
}
QByteArray HmacBlockStream::getHmacKey(quint64 blockIndex, QByteArray key)
QByteArray HmacBlockStream::getHmacKey(quint64 blockIndex, const QByteArray& key)
{
Q_ASSERT(key.size() == 64);
QByteArray indexBytes = Endian::sizedIntToBytes<quint64>(blockIndex, ByteOrder);

View File

@ -34,7 +34,7 @@ public:
bool reset() override;
void close() override;
static QByteArray getHmacKey(quint64 blockIndex, QByteArray key);
static QByteArray getHmacKey(quint64 blockIndex, const QByteArray& key);
bool atEnd() const override;

View File

@ -97,7 +97,7 @@ QSharedPointer<Totp::Settings> Totp::createSettings(const QString& key, const ui
});
}
QString Totp::writeSettings(const QSharedPointer<Totp::Settings> settings, const QString& title, const QString& username, bool forceOtp)
QString Totp::writeSettings(const QSharedPointer<Totp::Settings>& settings, const QString& title, const QString& username, bool forceOtp)
{
if (settings.isNull()) {
return {};
@ -127,7 +127,7 @@ QString Totp::writeSettings(const QSharedPointer<Totp::Settings> settings, const
return QString("%1;%2").arg(settings->step).arg(settings->digits);
}
QString Totp::generateTotp(const QSharedPointer<Totp::Settings> settings, const quint64 time)
QString Totp::generateTotp(const QSharedPointer<Totp::Settings>& settings, const quint64 time)
{
Q_ASSERT(!settings.isNull());
if (settings.isNull()) {
@ -194,7 +194,7 @@ Totp::Encoder& Totp::steamEncoder()
return getEncoderByShortName("S");
}
Totp::Encoder& Totp::getEncoderByShortName(QString shortName)
Totp::Encoder& Totp::getEncoderByShortName(const QString& shortName)
{
for (auto& encoder : encoders) {
if (encoder.shortName == shortName) {
@ -204,7 +204,7 @@ Totp::Encoder& Totp::getEncoderByShortName(QString shortName)
return defaultEncoder();
}
Totp::Encoder& Totp::getEncoderByName(QString name)
Totp::Encoder& Totp::getEncoderByName(const QString& name)
{
for (auto& encoder : encoders) {
if (encoder.name == name) {

View File

@ -60,15 +60,15 @@ static const QString ATTRIBUTE_SETTINGS = "TOTP Settings";
QSharedPointer<Totp::Settings> parseSettings(const QString& rawSettings, const QString& key = {});
QSharedPointer<Totp::Settings> createSettings(const QString& key, const uint digits, const uint step,
const QString& encoderShortName = {});
QString writeSettings(const QSharedPointer<Totp::Settings> settings, const QString& title = {},
QString writeSettings(const QSharedPointer<Totp::Settings>& settings, const QString& title = {},
const QString& username = {}, bool forceOtp = false);
QString generateTotp(const QSharedPointer<Totp::Settings> settings, const quint64 time = 0ull);
QString generateTotp(const QSharedPointer<Totp::Settings>& settings, const quint64 time = 0ull);
Encoder& defaultEncoder();
Encoder& steamEncoder();
Encoder& getEncoderByShortName(QString shortName);
Encoder& getEncoderByName(QString name);
Encoder& getEncoderByShortName(const QString& shortName);
Encoder& getEncoderByName(const QString& name);
}
#endif // QTOTP_H