From e852ed92f6a83d30d824cf3b35a8d3f68537fe9c Mon Sep 17 00:00:00 2001 From: PafXUS Date: Sat, 18 Jun 2016 07:49:40 +0300 Subject: [PATCH] fix(persistence): pass by reference to const --- src/persistence/db/rawdatabase.cpp | 2 +- src/persistence/db/rawdatabase.h | 2 +- src/persistence/profile.cpp | 6 +++--- src/persistence/profile.h | 6 +++--- src/persistence/settings.cpp | 4 ++-- src/persistence/settings.h | 4 ++-- src/persistence/settingsserializer.cpp | 2 +- src/persistence/settingsserializer.h | 2 +- 8 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/persistence/db/rawdatabase.cpp b/src/persistence/db/rawdatabase.cpp index 6c2024e09..83dedaf6d 100644 --- a/src/persistence/db/rawdatabase.cpp +++ b/src/persistence/db/rawdatabase.cpp @@ -312,7 +312,7 @@ bool RawDatabase::remove() } -QString RawDatabase::deriveKey(QString password) +QString RawDatabase::deriveKey(const QString &password) { if (password.isEmpty()) return {}; diff --git a/src/persistence/db/rawdatabase.h b/src/persistence/db/rawdatabase.h index 55c8b81c8..beab4ba8f 100644 --- a/src/persistence/db/rawdatabase.h +++ b/src/persistence/db/rawdatabase.h @@ -89,7 +89,7 @@ protected slots: protected: /// Derives a 256bit key from the password and returns it hex-encoded - static QString deriveKey(QString password); + static QString deriveKey(const QString &password); /// Extracts a variant from one column of a result row depending on the column type static QVariant extractData(sqlite3_stmt* stmt, int col); diff --git a/src/persistence/profile.cpp b/src/persistence/profile.cpp index babf0c8b6..c8f32d53b 100644 --- a/src/persistence/profile.cpp +++ b/src/persistence/profile.cpp @@ -37,7 +37,7 @@ QVector Profile::profiles; -Profile::Profile(QString name, QString password, bool isNewProfile) +Profile::Profile(QString name, const QString &password, bool isNewProfile) : name{name}, password{password}, newProfile{isNewProfile}, isRemoved{false} { @@ -65,7 +65,7 @@ Profile::Profile(QString name, QString password, bool isNewProfile) QObject::connect(coreThread, &QThread::started, core, &Core::start); } -Profile* Profile::loadProfile(QString name, QString password) +Profile* Profile::loadProfile(QString name, const QString &password) { if (ProfileLocker::hasLock()) { @@ -594,7 +594,7 @@ void Profile::restartCore() QMetaObject::invokeMethod(core, "reset"); } -void Profile::setPassword(QString newPassword) +void Profile::setPassword(const QString &newPassword) { QByteArray avatar = loadAvatarData(core->getSelfId().publicKey); QString oldPassword = password; diff --git a/src/persistence/profile.h b/src/persistence/profile.h index f02a5a1d1..d685b5af0 100644 --- a/src/persistence/profile.h +++ b/src/persistence/profile.h @@ -38,7 +38,7 @@ class Profile public: /// Locks and loads an existing profile and create the associate Core* instance /// Returns a nullptr on error, for example if the profile is already in use - static Profile* loadProfile(QString name, QString password = QString()); + static Profile* loadProfile(QString name, const QString &password = QString()); /// Creates a new profile and the associated Core* instance /// If password is not empty, the profile will be encrypted /// Returns a nullptr on error, for example if the profile already exists @@ -54,7 +54,7 @@ public: bool isEncrypted() const; ///< Returns true if we have a password set (doesn't check the actual file on disk) bool checkPassword(); ///< Checks whether the password is valid QString getPassword() const; - void setPassword(QString newPassword); ///< Changes the encryption password and re-saves everything with it + void setPassword(const QString &newPassword); ///< Changes the encryption password and re-saves everything with it const TOX_PASS_KEY& getPasskey() const; QByteArray loadToxSave(); ///< Loads the profile's .tox save from file, unencrypted @@ -93,7 +93,7 @@ public: static bool isEncrypted(QString name); ///< Returns false on error. Checks the actual file on disk. private: - Profile(QString name, QString password, bool newProfile); + Profile(QString name, const QString &password, bool newProfile); /// Lists all the files in the config dir with a given extension /// Pass the raw extension, e.g. "jpeg" not ".jpeg". static QVector getFilesByExt(QString extension); diff --git a/src/persistence/settings.cpp b/src/persistence/settings.cpp index 594fadc8a..f3c5cf0be 100644 --- a/src/persistence/settings.cpp +++ b/src/persistence/settings.cpp @@ -492,7 +492,7 @@ void Settings::savePersonal(Profile* profile) savePersonal(profile->getName(), profile->getPassword()); } -void Settings::savePersonal(QString profileName, QString password) +void Settings::savePersonal(QString profileName, const QString &password) { if (QThread::currentThread() != settingsThread) return (void) QMetaObject::invokeMethod(&getInstance(), "savePersonal", @@ -924,7 +924,7 @@ QString Settings::getToxmePass() const return toxmePass; } -void Settings::setToxmePass(QString pass) +void Settings::setToxmePass(const QString &pass) { QMutexLocker locker{&bigLock}; toxmePass = pass; diff --git a/src/persistence/settings.h b/src/persistence/settings.h index 15af3ae08..439cd2194 100644 --- a/src/persistence/settings.h +++ b/src/persistence/settings.h @@ -129,7 +129,7 @@ public: void setToxmePriv(bool priv); QString getToxmePass() const; - void setToxmePass(QString pass); + void setToxmePass(const QString &pass); void setAutoSaveEnabled(bool newValue); bool getAutoSaveEnabled() const; @@ -344,7 +344,7 @@ private: Settings& operator=(const Settings&) = delete; private slots: - void savePersonal(QString profileName, QString password); + void savePersonal(QString profileName, const QString &password); private: bool loaded; diff --git a/src/persistence/settingsserializer.cpp b/src/persistence/settingsserializer.cpp index 80b36bb71..df8ac02d2 100644 --- a/src/persistence/settingsserializer.cpp +++ b/src/persistence/settingsserializer.cpp @@ -72,7 +72,7 @@ QDataStream& readStream(QDataStream& dataStream, QByteArray& data) return dataStream; } -SettingsSerializer::SettingsSerializer(QString filePath, QString password) +SettingsSerializer::SettingsSerializer(QString filePath, const QString &password) : path{filePath}, password{password}, group{-1}, array{-1}, arrayIndex{-1} { diff --git a/src/persistence/settingsserializer.h b/src/persistence/settingsserializer.h index c57dc48da..58795ab97 100644 --- a/src/persistence/settingsserializer.h +++ b/src/persistence/settingsserializer.h @@ -34,7 +34,7 @@ class SettingsSerializer { public: - SettingsSerializer(QString filePath, QString password=QString()); + SettingsSerializer(QString filePath, const QString &password=QString()); static bool isSerializedFormat(QString filePath); ///< Check if the file is serialized settings. False on error.