Skip to content

Commit

Permalink
cleanup: Don't move trivially copyable values.
Browse files Browse the repository at this point in the history
```sh
run-clang-tidy -p _build -fix $(find . -name "*.h" -or -name "*.cpp" \
    -or -name "*.c" | grep -v "/_build/") \
    -checks="-*,performance-move-const-arg"
```
  • Loading branch information
iphydf committed Jan 14, 2025
1 parent f2d8104 commit 7af913e
Show file tree
Hide file tree
Showing 14 changed files with 34 additions and 34 deletions.
1 change: 1 addition & 0 deletions .clang-tidy
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Checks: "-*
, modernize-use-equals-*
, modernize-use-nullptr
, modernize-use-override
, performance-move-const-arg
, readability-container-*
, readability-else-after-return
, readability-make-member-function-const
Expand Down
9 changes: 3 additions & 6 deletions src/core/chatid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,16 @@
/**
* @brief The default constructor. Creates an empty id.
*/
ChatId::ChatId()
: id()
{
}
ChatId::ChatId() = default;
ChatId::~ChatId() = default;

/**
* @brief Constructs a ChatId from bytes.
* @param rawId The bytes to construct the ChatId from.
*/
ChatId::ChatId(const QByteArray& rawId)
ChatId::ChatId(QByteArray rawId)
: id(std::move(rawId))
{
id = rawId;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/core/chatid.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class ChatId

protected:
ChatId();
explicit ChatId(const QByteArray& rawId);
explicit ChatId(QByteArray rawId);
QByteArray id;
};

Expand Down
9 changes: 6 additions & 3 deletions src/core/toxpk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@ ToxPk::ToxPk()
ToxPk::ToxPk(QByteArray rawId)
: ChatId(std::move(rawId))
{
assert(rawId.length() == size);
if (id.length() != size) {
qFatal("ToxPk constructed with invalid length (%u instead of %d)",
static_cast<uint>(id.length()), size);
}
}

/**
Expand All @@ -55,8 +58,8 @@ ToxPk::ToxPk(const uint8_t* rawId)
ToxPk::ToxPk(const QString& pk)
: ToxPk([&pk]() {
if (pk.length() != numHexChars) {
assert(!"ToxPk constructed with invalid length string");
return QByteArray(); // invalid pk string
qFatal("ToxPk constructed with invalid length string (%u instead of %d)",
static_cast<uint>(pk.length()), numHexChars);
}
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 @@ -13,7 +13,7 @@ class ToxPk : public ChatId
{
public:
static constexpr int size = 32;
static constexpr int numHexChars = 64;
static constexpr int numHexChars = size * 2;
ToxPk();
explicit ToxPk(QByteArray rawId);
explicit ToxPk(const uint8_t* rawId);
Expand Down
2 changes: 1 addition & 1 deletion src/model/friendmessagedispatcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ FriendMessageDispatcher::FriendMessageDispatcher(Friend& f_, MessageProcessor pr
ICoreFriendMessageSender& messageSender_)
: f(f_)
, messageSender(messageSender_)
, processor(std::move(processor_))
, processor(processor_)
{
connect(&f, &Friend::onlineOfflineChanged, this,
&FriendMessageDispatcher::onFriendOnlineOfflineChanged);
Expand Down
5 changes: 0 additions & 5 deletions src/model/ichatlog.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,9 @@

#pragma once

#include "message.h"
#include "src/conferencelist.h"
#include "src/core/toxfile.h"
#include "src/core/toxpk.h"
#include "src/friendlist.h"
#include "src/model/chatlogitem.h"
#include "src/model/conference.h"
#include "src/model/friend.h"
#include "src/model/systemmessage.h"
#include "src/widget/searchtypes.h"
#include "util/strongtype.h"
Expand Down
4 changes: 2 additions & 2 deletions src/model/message.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,15 +92,15 @@ class MessageProcessor
/**
* @brief Enables mention detection in the processor
*/
inline void enableMentions()
void enableMentions()
{
detectingMentions = true;
}

/**
* @brief Disables mention detection in the processor
*/
inline void disableMentions()
void disableMentions()
{
detectingMentions = false;
}
Expand Down
6 changes: 1 addition & 5 deletions src/model/sessionchatlog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -283,11 +283,7 @@ std::vector<IChatLog::DateChatLogIdxPair> SessionChatLog::getDateIdxs(const QDat
break;
}

DateChatLogIdxPair pair;
pair.date = dateIt;
pair.idx = it->first;

ret.push_back(std::move(pair));
ret.emplace_back(DateChatLogIdxPair{dateIt, it->first});

dateIt = dateIt.addDays(1);
if (startDate.daysTo(dateIt) > static_cast<long>(maxDates) && maxDates != 0) {
Expand Down
1 change: 1 addition & 0 deletions src/model/sessionchatlog.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

#include "ichatlog.h"
#include "imessagedispatcher.h"
#include "src/core/icoreidhandler.h"

#include <QList>
#include <QObject>
Expand Down
7 changes: 6 additions & 1 deletion src/persistence/db/upgrades/dbupgrader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ bool DbUpgrader::dbSchemaUpgrade(std::shared_ptr<RawDatabase>& db, IMessageBoxMa

// Otherwise we have to do upgrades from our current version to the latest version

int64_t databaseSchemaVersion;
int64_t databaseSchemaVersion = -1;

if (!db->execNow(RawDatabase::Query("PRAGMA user_version", [&](const QVector<QVariant>& row) {
databaseSchemaVersion = row[0].toLongLong();
Expand All @@ -221,6 +221,11 @@ bool DbUpgrader::dbSchemaUpgrade(std::shared_ptr<RawDatabase>& db, IMessageBoxMa
return false;
}

if (databaseSchemaVersion < 0) {
qCritical() << "Failed to read database schema version";
return false;
}

if (databaseSchemaVersion > SCHEMA_VERSION) {
messageBoxManager.showError(QObject::tr("Failed to load chat history"),
QObject::tr("Database version (%1) is newer than we currently "
Expand Down
2 changes: 1 addition & 1 deletion src/platform/camera/v4l2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ QVector<VideoMode> v4l2::getDeviceModes(QString devName)
for (float rate : rates) {
mode.fps = rate;
if (!modes.contains(mode)) {
modes.append(std::move(mode));
modes.append(mode);
}
}
vfse.index++;
Expand Down
9 changes: 5 additions & 4 deletions src/widget/widget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1178,9 +1178,10 @@ void Widget::addFriend(uint32_t friendId, const ToxPk& friendPk)
connectFriendWidget(*widget);
auto history = profile.getHistory();

auto messageProcessor = MessageProcessor(*sharedMessageProcessorParams);
auto friendMessageDispatcher =
std::make_shared<FriendMessageDispatcher>(*newFriend, std::move(messageProcessor), *core);
std::make_shared<FriendMessageDispatcher>(*newFriend,
MessageProcessor(*sharedMessageProcessorParams),
*core);

// Note: We do not have to connect the message dispatcher signals since
// ChatHistory hooks them up in a very specific order
Expand Down Expand Up @@ -2123,9 +2124,9 @@ Conference* Widget::createConference(uint32_t conferencenumber, const Conference

const auto compact = settings.getCompactLayout();
auto widget = new ConferenceWidget(chatroom, compact, settings, style);
auto messageProcessor = MessageProcessor(*sharedMessageProcessorParams);
auto messageDispatcher =
std::make_shared<ConferenceMessageDispatcher>(*newConference, std::move(messageProcessor),
std::make_shared<ConferenceMessageDispatcher>(*newConference,
MessageProcessor(*sharedMessageProcessorParams),
*core, *core, settings);

auto history = profile.getHistory();
Expand Down
9 changes: 5 additions & 4 deletions test/core/chatid_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@

#include "src/core/chatid.h"
#include "src/core/conferenceid.h"
#include "src/core/toxid.h"
#include "src/core/toxpk.h"

#include <QByteArray>
#include <QString>
#include <QtTest/QtTest>

const uint8_t testPkArray[32] = {0xC7, 0x71, 0x9C, 0x68, 0x08, 0xC1, 0x4B, 0x77, 0x34, 0x80, 0x04,
0x95, 0x6D, 0x1D, 0x98, 0x04, 0x6C, 0xE0, 0x9A, 0x34, 0x37, 0x0E,
0x76, 0x08, 0x15, 0x0E, 0xAD, 0x74, 0xC3, 0x81, 0x5D, 0x30};
const uint8_t testPkArray[32] = {
0xC7, 0x71, 0x9C, 0x68, 0x08, 0xC1, 0x4B, 0x77, 0x34, 0x80, 0x04, 0x95, 0x6D, 0x1D, 0x98, 0x04,
0x6C, 0xE0, 0x9A, 0x34, 0x37, 0x0E, 0x76, 0x08, 0x15, 0x0E, 0xAD, 0x74, 0xC3, 0x81, 0x5D, 0x30,
};

const QString testStr =
QStringLiteral("C7719C6808C14B77348004956D1D98046CE09A34370E7608150EAD74C3815D30");
Expand All @@ -39,6 +39,7 @@ private slots:

void TestChatId::toStringTest()
{
QCOMPARE(testPk.size(), ToxPk::size);
ToxPk pk(testPk);
QVERIFY(testStr == pk.toString());
}
Expand Down

0 comments on commit 7af913e

Please sign in to comment.