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

cleanup: Pass moved-from objects by value instead of const ref. #80

Merged
merged 1 commit into from
Jan 13, 2025
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
1 change: 1 addition & 0 deletions .clang-tidy
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Checks: "-*
, modernize-loop-convert
, modernize-make-shared
, modernize-make-unique
, modernize-pass-by-value
, modernize-return-braced-init-list
, modernize-use-bool-literals
, modernize-use-emplace
Expand Down
10 changes: 5 additions & 5 deletions src/chatlog/chatlinestorage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
ChatLineStorage::iterator ChatLineStorage::insertChatMessage(ChatLogIdx idx, QDateTime timestamp,
ChatLine::Ptr line)
{
if (idxInfoMap.find(idx) != idxInfoMap.end()) {
if (idxInfoMap.contains(idx)) {
qWarning() << "Index is already rendered, not updating";
return lines.end();
}
Expand Down Expand Up @@ -200,9 +200,9 @@ void ChatLineStorage::decrementLinePosAfter(IdxInfoMap_t::iterator inputIt)

bool ChatLineStorage::shouldRemovePreviousLine(iterator prevIt, iterator it)
{
return prevIt != lines.end() && // Previous iterator is valid
dateMap.find(*prevIt) != dateMap.end() && // Previous iterator is a date line
(it == lines.end() || // Previous iterator is the last line
dateMap.find(*it) != dateMap.end() // Adjacent date lines
return prevIt != lines.end() && // Previous iterator is valid
dateMap.contains(*prevIt) && // Previous iterator is a date line
(it == lines.end() || // Previous iterator is the last line
dateMap.contains(*it) // Adjacent date lines
);
}
2 changes: 1 addition & 1 deletion src/chatlog/chatlinestorage.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ class ChatLineStorage

bool contains(ChatLogIdx idx) const
{
return idxInfoMap.find(idx) != idxInfoMap.end();
return idxInfoMap.contains(idx);
}

bool contains(QDateTime timestamp) const;
Expand Down
5 changes: 3 additions & 2 deletions src/chatlog/content/text.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,12 @@
#include <QPalette>
#include <QTextBlock>
#include <QTextFragment>
#include <utility>

Text::Text(DocumentCache& documentCache_, Settings& settings_, Style& style_, const QColor& custom,
const QString& txt, const QFont& font, bool enableElide, const QString& rawText_,
const QString& txt, const QFont& font, bool enableElide, QString rawText_,
const TextType& type)
: rawText(rawText_)
: rawText(std::move(rawText_))
, elide(enableElide)
, defFont(font)
, textType(type)
Expand Down
2 changes: 1 addition & 1 deletion src/chatlog/content/text.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class Text : public ChatLineContent

Text(DocumentCache& documentCache, Settings& settings, Style& style, const QColor& custom,
const QString& txt = "", const QFont& font = QFont(), bool enableElide = false,
const QString& rawText = QString(), const TextType& type = NORMAL);
QString rawText = QString(), const TextType& type = NORMAL);
Text(DocumentCache& documentCache, Settings& settings, Style& style, const QString& txt = "",
const QFont& font = QFont(), bool enableElide = false, const QString& rawText = QString(),
const TextType& type = NORMAL);
Expand Down
4 changes: 2 additions & 2 deletions src/core/coreav.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ void CoreAV::process()
bool CoreAV::isCallStarted(const Friend* f) const
{
QReadLocker locker{&callsLock};
return f && (calls.find(f->getId()) != calls.end());
return f && calls.contains(f->getId());
}

/**
Expand All @@ -199,7 +199,7 @@ bool CoreAV::isCallStarted(const Friend* f) const
bool CoreAV::isCallStarted(const Conference* c) const
{
QReadLocker locker{&callsLock};
return c && (conferenceCalls.find(c->getId()) != conferenceCalls.end());
return c && conferenceCalls.contains(c->getId());
}

/**
Expand Down
3 changes: 2 additions & 1 deletion src/core/toxfile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <QFile>
#include <QRegularExpression>
#include <tox/tox.h>
#include <utility>

#define TOX_HEX_ID_LENGTH 2 * TOX_ADDRESS_SIZE

Expand Down Expand Up @@ -38,7 +39,7 @@ ToxFile::ToxFile(uint32_t fileNum_, uint32_t friendId_, QString fileName_, QStri
: fileKind{TOX_FILE_KIND_DATA}
, fileNum(fileNum_)
, friendId(friendId_)
, fileName{fileName_}
, fileName{std::move(fileName_)}
, filePath{filePath_}
, file{new QFile(filePath_)}
, status{INITIALIZING}
Expand Down
5 changes: 3 additions & 2 deletions src/core/toxoptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,17 @@

#include <QByteArray>
#include <QDebug>
#include <utility>

/**
* @brief The ToxOptions class wraps the Tox_Options struct and the matching
* proxy address data. This is needed to ensure both have equal lifetime and
* are correctly deleted.
*/

ToxOptions::ToxOptions(Tox_Options* options_, const QByteArray& proxyAddrData_)
ToxOptions::ToxOptions(Tox_Options* options_, QByteArray proxyAddrData_)
: options(options_)
, proxyAddrData(proxyAddrData_)
, proxyAddrData(std::move(proxyAddrData_))
{
}

Expand Down
2 changes: 1 addition & 1 deletion src/core/toxoptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class ToxOptions
void setIPv6Enabled(bool enabled);

private:
ToxOptions(Tox_Options* options_, const QByteArray& proxyAddrData_);
ToxOptions(Tox_Options* options_, QByteArray proxyAddrData_);

private:
Tox_Options* options = nullptr;
Expand Down
20 changes: 9 additions & 11 deletions src/core/toxpk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,10 @@ ToxPk::ToxPk()
* @param rawId The bytes to construct the ToxPk from. The length must be exactly
* ToxPk::size, else the ToxPk will be empty.
*/
ToxPk::ToxPk(const QByteArray& rawId)
: ChatId([&rawId]() {
assert(rawId.length() == size);
return rawId;
}())
ToxPk::ToxPk(QByteArray rawId)
: ChatId(std::move(rawId))
{
assert(rawId.length() == size);
}

/**
Expand All @@ -43,7 +41,7 @@ ToxPk::ToxPk(const QByteArray& rawId)
* ToxPk::size from the specified buffer.
*/
ToxPk::ToxPk(const uint8_t* rawId)
: ChatId(QByteArray(reinterpret_cast<const char*>(rawId), size))
: ToxPk(QByteArray(reinterpret_cast<const char*>(rawId), size))
{
}

Expand All @@ -55,12 +53,12 @@ ToxPk::ToxPk(const uint8_t* rawId)
* @param pk Tox Pk string to convert to ToxPk object
*/
ToxPk::ToxPk(const QString& pk)
: ChatId([&pk]() {
if (pk.length() == numHexChars) {
return QByteArray::fromHex(pk.toLatin1());
: ToxPk([&pk]() {
if (pk.length() != numHexChars) {
assert(!"ToxPk constructed with invalid length string");
return QByteArray(); // invalid pk string
}
assert(!"ToxPk constructed with invalid length string");
return QByteArray(); // invalid pk string
return QByteArray::fromHex(pk.toLatin1());
}())
{
}
Expand Down
2 changes: 1 addition & 1 deletion src/core/toxpk.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class ToxPk : public ChatId
static constexpr int size = 32;
static constexpr int numHexChars = 64;
ToxPk();
explicit ToxPk(const QByteArray& rawId);
explicit ToxPk(QByteArray rawId);
explicit ToxPk(const uint8_t* rawId);
explicit ToxPk(const QString& pk);
int getSize() const override;
Expand Down
5 changes: 3 additions & 2 deletions src/core/toxstring.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

#include <cassert>
#include <climits>
#include <utility>

/**
* @class ToxString
Expand All @@ -31,8 +32,8 @@ ToxString::ToxString(const QString& text)
* @brief Creates a ToxString from bytes in a QByteArray.
* @param text Input text.
*/
ToxString::ToxString(const QByteArray& text)
: string(text)
ToxString::ToxString(QByteArray text)
: string(std::move(text))
{
}

Expand Down
2 changes: 1 addition & 1 deletion src/core/toxstring.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class ToxString
{
public:
explicit ToxString(const QString& text);
explicit ToxString(const QByteArray& text);
explicit ToxString(QByteArray text);
ToxString(const uint8_t* text, size_t length);

const uint8_t* data() const;
Expand Down
5 changes: 3 additions & 2 deletions src/model/chatlogitem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "src/model/friend.h"

#include <cassert>
#include <utility>

namespace {

Expand Down Expand Up @@ -44,10 +45,10 @@ ChatLogItem::ChatLogItem(SystemMessage systemMessage)
{
}

ChatLogItem::ChatLogItem(ToxPk sender_, const QString& displayName_, ContentType contentType_,
ChatLogItem::ChatLogItem(ToxPk sender_, QString displayName_, ContentType contentType_,
ContentPtr content_)
: sender(std::move(sender_))
, displayName(displayName_)
, displayName(std::move(displayName_))
, contentType(contentType_)
, content(std::move(content_))
{
Expand Down
2 changes: 1 addition & 1 deletion src/model/chatlogitem.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class ChatLogItem
const QString& getDisplayName() const;

private:
ChatLogItem(ToxPk sender, const QString& displayName_, ContentType contentType, ContentPtr content);
ChatLogItem(ToxPk sender, QString displayName_, ContentType contentType, ContentPtr content);

ToxPk sender;
QString displayName;
Expand Down
12 changes: 6 additions & 6 deletions src/model/conference.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,19 @@
#include <cassert>

#include <QDebug>
#include <utility>

namespace {
const int MAX_CONFERENCE_TITLE_LENGTH = 128;
} // namespace

Conference::Conference(int conferenceId_, const ConferenceId persistentConferenceId,
const QString& name, bool isAvConference, const QString& selfName_,
ICoreConferenceQuery& conferenceQuery_, ICoreIdHandler& idHandler_,
FriendList& friendList_)
Conference::Conference(int conferenceId_, const ConferenceId persistentConferenceId, QString name,
bool isAvConference, QString selfName_, ICoreConferenceQuery& conferenceQuery_,
ICoreIdHandler& idHandler_, FriendList& friendList_)
: conferenceQuery(conferenceQuery_)
, idHandler(idHandler_)
, selfName{selfName_}
, title{name}
, selfName{std::move(selfName_)}
, title{std::move(name)}
, toxConferenceNum(conferenceId_)
, conferenceId{persistentConferenceId}
, avConference{isAvConference}
Expand Down
4 changes: 2 additions & 2 deletions src/model/conference.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ class Conference : public Chat
{
Q_OBJECT
public:
Conference(int conferenceId_, const ConferenceId persistentConferenceId, const QString& name,
bool isAvConference, const QString& selfName_, ICoreConferenceQuery& conferenceQuery_,
Conference(int conferenceId_, const ConferenceId persistentConferenceId, QString name,
bool isAvConference, QString selfName_, ICoreConferenceQuery& conferenceQuery_,
ICoreIdHandler& idHandler_, FriendList& friendList);
bool isAvConference() const;
uint32_t getId() const override;
Expand Down
6 changes: 4 additions & 2 deletions src/model/conferenceinvite.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,18 @@

#include "conferenceinvite.h"

#include <utility>

/**
* @class ConferenceInvite
*
* @brief This class contains information needed to create a conference invite
*/

ConferenceInvite::ConferenceInvite(uint32_t friendId_, uint8_t inviteType, const QByteArray& data)
ConferenceInvite::ConferenceInvite(uint32_t friendId_, uint8_t inviteType, QByteArray data)
: friendId{friendId_}
, type{inviteType}
, invite{data}
, invite{std::move(data)}
, date{QDateTime::currentDateTime()}
{
}
Expand Down
2 changes: 1 addition & 1 deletion src/model/conferenceinvite.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class ConferenceInvite
{
public:
ConferenceInvite() = default;
ConferenceInvite(uint32_t friendId_, uint8_t inviteType, const QByteArray& data);
ConferenceInvite(uint32_t friendId_, uint8_t inviteType, QByteArray data);
bool operator==(const ConferenceInvite& other) const;

uint32_t getFriendId() const;
Expand Down
13 changes: 6 additions & 7 deletions src/model/friend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,17 @@
#include <QDebug>

#include <cassert>
#include <memory>
#include <utility>

Friend::Friend(uint32_t friendId_, const ToxPk& friendPk_, const QString& userAlias_,
const QString& userName_)
: userName{userName_}
, userAlias{userAlias_}
, friendPk{friendPk_}
Friend::Friend(uint32_t friendId_, ToxPk friendPk_, QString userAlias_, QString userName_)
: userName{std::move(userName_)}
, userAlias{std::move(userAlias_)}
, friendPk{std::move(friendPk_)}
, friendId{friendId_}
, hasNewEvents{false}
, friendStatus{Status::Status::Offline}
{
if (userName_.isEmpty()) {
if (userName.isEmpty()) {
userName = friendPk.toString();
}
}
Expand Down
3 changes: 1 addition & 2 deletions src/model/friend.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ class Friend : public Chat
{
Q_OBJECT
public:
Friend(uint32_t friendId_, const ToxPk& friendPk_, const QString& userAlias_ = {},
const QString& userName_ = {});
Friend(uint32_t friendId_, ToxPk friendPk_, QString userAlias_ = {}, QString userName_ = {});
Friend(const Friend& other) = delete;
Friend& operator=(const Friend& other) = delete;

Expand Down
5 changes: 3 additions & 2 deletions src/persistence/db/rawdatabase.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <QVector>

#include <functional>
#include <utility>
#include <vector>

struct sqlite3_stmt;
Expand Down Expand Up @@ -48,7 +49,7 @@ class RawDatabase
Query(QString query_, QVector<QByteArray> blobs_ = {},
const std::function<void(RowId)>& insertCallback_ = {})
: query{query_.toUtf8()}
, blobs{blobs_}
, blobs{std::move(blobs_)}
, insertCallback{insertCallback_}
{
}
Expand All @@ -65,7 +66,7 @@ class RawDatabase
Query(QString query_, QVector<QByteArray> blobs_,
const std::function<void(const QVector<QVariant>&)>& rowCallback_)
: query{query_.toUtf8()}
, blobs{blobs_}
, blobs{std::move(blobs_)}
, rowCallback{rowCallback_}
{
}
Expand Down
9 changes: 5 additions & 4 deletions src/persistence/db/rawdatabaseimpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,19 @@
#include <QFile>
#include <QMetaObject>
#include <QMutexLocker>
#include <utility>

/**
* @brief Tries to open a database.
* @param path Path to database.
* @param password If empty, the database will be opened unencrypted.
* Otherwise we will use toxencryptsave to derive a key and encrypt the database.
*/
RawDatabaseImpl::RawDatabaseImpl(const QString& path_, const QString& password, const QByteArray& salt)
RawDatabaseImpl::RawDatabaseImpl(QString path_, const QString& password, QByteArray salt)
: workerThread{new QThread}
, path{path_}
, currentSalt{salt} // we need the salt later if a new password should be set
, currentHexKey{deriveKey(password, salt)}
, path{std::move(path_)}
, currentSalt{std::move(salt)} // we need the salt later if a new password should be set
, currentHexKey{deriveKey(password, currentSalt)}
{
workerThread->setObjectName("qTox Database");
moveToThread(workerThread.get());
Expand Down
2 changes: 1 addition & 1 deletion src/persistence/db/rawdatabaseimpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class RawDatabaseImpl final : QObject, public RawDatabase
p4_0 // SQLCipher 4.0 default encryption params
};

RawDatabaseImpl(const QString& path_, const QString& password, const QByteArray& salt);
RawDatabaseImpl(QString path_, const QString& password, QByteArray salt);
~RawDatabaseImpl() override;
bool isOpen() override;

Expand Down
Loading
Loading