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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
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
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
5 changes: 3 additions & 2 deletions src/core/toxstring.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

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

/**
* @class ToxString
Expand All @@ -29,8 +30,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/group.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
8 changes: 4 additions & 4 deletions src/model/friend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@

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

Friend::Friend(uint32_t friendId_, const ToxPk& friendPk_, const QString& userAlias_,
const QString& userName_)
Friend::Friend(uint32_t friendId_, ToxPk friendPk_, QString userAlias_, const QString& userName_)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know this is what clang-tidy's autofix did, but it's odd that userName_ isn't by-value when the other QStrings are.

: userName{userName_}
, userAlias{userAlias_}
, friendPk{friendPk_}
, userAlias{std::move(userAlias_)}
, friendPk{std::move(friendPk_)}
, friendId{friendId_}
, hasNewEvents{false}
, friendStatus{Status::Status::Offline}
Expand Down
3 changes: 1 addition & 2 deletions src/model/friend.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,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_ = {}, const QString& userName_ = {});
Friend(const Friend& other) = delete;
Friend& operator=(const Friend& other) = delete;

Expand Down
9 changes: 5 additions & 4 deletions src/model/group.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,19 @@
#include <cassert>

#include <QDebug>
#include <utility>

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

Group::Group(int groupId_, const GroupId persistentGroupId, const QString& name, bool isAvGroupchat,
const QString& selfName_, ICoreGroupQuery& groupQuery_, ICoreIdHandler& idHandler_,
Group::Group(int groupId_, const GroupId persistentGroupId, QString name, bool isAvGroupchat,
QString selfName_, ICoreGroupQuery& groupQuery_, ICoreIdHandler& idHandler_,
FriendList& friendList_)
: groupQuery(groupQuery_)
, idHandler(idHandler_)
, selfName{selfName_}
, title{name}
, selfName{std::move(selfName_)}
, title{std::move(name)}
, toxGroupNum(groupId_)
, groupId{persistentGroupId}
, avGroupchat{isAvGroupchat}
Expand Down
4 changes: 2 additions & 2 deletions src/model/group.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ class Group : public Chat
{
Q_OBJECT
public:
Group(int groupId_, const GroupId persistentGroupId, const QString& name, bool isAvGroupchat,
const QString& selfName_, ICoreGroupQuery& groupQuery_, ICoreIdHandler& idHandler_,
Group(int groupId_, const GroupId persistentGroupId, QString name, bool isAvGroupchat,
QString selfName_, ICoreGroupQuery& groupQuery_, ICoreIdHandler& idHandler_,
FriendList& friendList);
bool isAvGroupchat() const;
uint32_t getId() const override;
Expand Down
6 changes: 4 additions & 2 deletions src/model/groupinvite.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,18 @@

#include "groupinvite.h"

#include <utility>

/**
* @class GroupInvite
*
* @brief This class contains information needed to create a group invite
*/

GroupInvite::GroupInvite(uint32_t friendId_, uint8_t inviteType, const QByteArray& data)
GroupInvite::GroupInvite(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/groupinvite.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class GroupInvite
{
public:
GroupInvite() = default;
GroupInvite(uint32_t friendId_, uint8_t inviteType, const QByteArray& data);
GroupInvite(uint32_t friendId_, uint8_t inviteType, QByteArray data);
bool operator==(const GroupInvite& other) const;

uint32_t getFriendId() const;
Expand Down
5 changes: 3 additions & 2 deletions src/persistence/db/rawdatabase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include <QFile>
#include <QMetaObject>
#include <QMutexLocker>
#include <utility>


/**
Expand Down Expand Up @@ -70,9 +71,9 @@
* @param password If empty, the database will be opened unencrypted.
* Otherwise we will use toxencryptsave to derive a key and encrypt the database.
*/
RawDatabase::RawDatabase(const QString& path_, const QString& password, const QByteArray& salt)
RawDatabase::RawDatabase(QString path_, const QString& password, const QByteArray& salt)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No by-value+std::move for QByteArray like in other files?

: workerThread{new QThread}
, path{path_}
, path{std::move(path_)}
, currentSalt{salt} // we need the salt later if a new password should be set
, currentHexKey{deriveKey(password, salt)}
{
Expand Down
2 changes: 1 addition & 1 deletion src/persistence/db/rawdatabase.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ class RawDatabase : QObject
p4_0 // SQLCipher 4.0 default encryption params
};

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

Expand Down
3 changes: 2 additions & 1 deletion src/persistence/db/upgrades/dbupgrader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include <QDebug>
#include <QString>
#include <QTranslator>
#include <utility>

namespace {
constexpr int SCHEMA_VERSION = 11;
Expand Down Expand Up @@ -62,7 +63,7 @@ struct DuplicateAlias
{
DuplicateAlias(RowId goodAliasRow_, std::vector<RowId> badAliasRows_)
: goodAliasRow{goodAliasRow_}
, badAliasRows{badAliasRows_}
, badAliasRows{std::move(badAliasRows_)}
{
}
DuplicateAlias() {}
Expand Down
3 changes: 2 additions & 1 deletion src/persistence/history.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

#include <QDebug>
#include <cassert>
#include <utility>

#include <tox/tox.h>

Expand Down Expand Up @@ -171,7 +172,7 @@ FileDbInsertionData::FileDbInsertionData()
*/
History::History(std::shared_ptr<RawDatabase> db_, Settings& settings_,
IMessageBoxManager& messageBoxManager)
: db(db_)
: db(std::move(db_))
, settings(settings_)
{
if (!isValid()) {
Expand Down
6 changes: 3 additions & 3 deletions src/persistence/profile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

#include <cassert>
#include <sodium.h>
#include <utility>

#include "profile.h"
#include "profilelocker.h"
Expand Down Expand Up @@ -281,9 +282,8 @@ void Profile::initCore(const QByteArray& toxsave, Settings& s, bool isNewProfile
avatarBroadcaster = std::unique_ptr<AvatarBroadcaster>(new AvatarBroadcaster(*core));
}

Profile::Profile(const QString& name_, std::unique_ptr<ToxEncrypt> passkey_, Paths& paths_,
Settings& settings_)
: name{name_}
Profile::Profile(QString name_, std::unique_ptr<ToxEncrypt> passkey_, Paths& paths_, Settings& settings_)
: name{std::move(name_)}
, passkey{std::move(passkey_)}
, isRemoved{false}
, encrypted{passkey != nullptr}
Expand Down
3 changes: 1 addition & 2 deletions src/persistence/profile.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,7 @@ private slots:
uint64_t filesize);

private:
Profile(const QString& name_, std::unique_ptr<ToxEncrypt> passkey_, Paths& paths_,
Settings& settings_);
Profile(QString name_, std::unique_ptr<ToxEncrypt> passkey_, Paths& paths_, Settings& settings_);
static QStringList getFilesByExt(QString extension, Settings& settings);
QString avatarPath(const ToxPk& owner, bool forceUnencrypted = false);
bool saveToxSave(QByteArray data);
Expand Down
3 changes: 2 additions & 1 deletion src/persistence/settingsserializer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include <QSaveFile>
#include <cassert>
#include <memory>
#include <utility>

/**
* @class SettingsSerializer
Expand Down Expand Up @@ -84,7 +85,7 @@ QDataStream& readStream(QDataStream& dataStream, QByteArray& data)
} // namespace

SettingsSerializer::SettingsSerializer(QString filePath_, const ToxEncrypt* passKey_)
: path{filePath_}
: path{std::move(filePath_)}
, passKey{passKey_}
, group{-1}
, array{-1}
Expand Down
5 changes: 3 additions & 2 deletions src/video/cameradevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <QApplication>
#include <QDebug>
#include <QScreen>
#include <utility>
extern "C"
{
#pragma GCC diagnostic push
Expand Down Expand Up @@ -65,8 +66,8 @@ AvFindInputFormatRet iformat{nullptr};
QHash<QString, CameraDevice*> CameraDevice::openDevices;
QMutex CameraDevice::openDeviceLock, CameraDevice::iformatLock;

CameraDevice::CameraDevice(const QString& devName_, AVFormatContext* context_)
: devName{devName_}
CameraDevice::CameraDevice(QString devName_, AVFormatContext* context_)
: devName{std::move(devName_)}
, context{context_}
, refcount{1}
{
Expand Down
2 changes: 1 addition & 1 deletion src/video/cameradevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class CameraDevice
static bool isScreen(const QString& devName);

private:
CameraDevice(const QString& devName_, AVFormatContext* context_);
CameraDevice(QString devName_, AVFormatContext* context_);
static CameraDevice* open(QString devName, AVDictionary** options);
static bool getDefaultInputFormat();
static QVector<QPair<QString, QString>> getRawDeviceListGeneric();
Expand Down
3 changes: 2 additions & 1 deletion src/video/netcamview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include <QLabel>
#include <QPushButton>
#include <QScreen>
#include <utility>

namespace {
const auto BTN_STATE_NONE = QVariant("none");
Expand All @@ -35,7 +36,7 @@ NetCamView::NetCamView(ToxPk friendPk_, CameraSource& cameraSource_, Settings& s
Style& style_, Profile& profile, QWidget* parent)
: QWidget(parent)
, selfFrame{nullptr}
, friendPk{friendPk_}
, friendPk{std::move(friendPk_)}
, e(false)
, cameraSource{cameraSource_}
, settings{settings_}
Expand Down
5 changes: 3 additions & 2 deletions src/video/videosurface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include <QDebug>
#include <QLabel>
#include <QPainter>
#include <utility>

namespace {
float getSizeRatio(const QSize size)
Expand All @@ -27,12 +28,12 @@ float getSizeRatio(const QSize size)
* @var std::atomic_bool VideoSurface::frameLock
* @brief Fast lock for lastFrame.
*/
VideoSurface::VideoSurface(const QPixmap& avatar_, QWidget* parent, bool expanding_)
VideoSurface::VideoSurface(QPixmap avatar_, QWidget* parent, bool expanding_)
: QWidget{parent}
, source{nullptr}
, frameLock{false}
, hasSubscribed{0}
, avatar{avatar_}
, avatar{std::move(avatar_)}
, ratio{1.0f}
, expanding{expanding_}
{
Expand Down
Loading
Loading