From 5038ae0a0099c2a5c6ffdd08734b597d92edac70 Mon Sep 17 00:00:00 2001 From: Kitsune Ral Date: Sun, 7 May 2017 20:02:34 +0900 Subject: Code cleanup and tweaking (partially driven by clang-tidy) Mainly it's about const-ification (in particular, passing const-refs instead of values) and deleting unneeded declarations/#includes. Since the changes alter the external interface, this is submitted as a PR for peer review. One of unneeded declarations/definitions is a virtual destructor in BaseJob descendants. Since a job object should be deleted through QObject::deleteLater() anyway (and it's the only correct way of disposing of the object), all deletions will call the stack of destructors through virtual QObject::~QObject(). Therefore even BaseJob could get on with a non-virtual destructor but for the sake of clarity BaseJob::~BaseJob() is still declared virtual. --- jobs/syncjob.h | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) (limited to 'jobs/syncjob.h') diff --git a/jobs/syncjob.h b/jobs/syncjob.h index b41c09d4..21d3cfca 100644 --- a/jobs/syncjob.h +++ b/jobs/syncjob.h @@ -34,7 +34,7 @@ namespace QMatrixClient private: QString jsonKey; public: - explicit EventList(QString k) : jsonKey(k) { } + explicit EventList(QString k) : jsonKey(std::move(k)) { } void fromJson(const QJsonObject& roomContents); }; @@ -51,11 +51,10 @@ namespace QMatrixClient int highlightCount; int notificationCount; - SyncRoomData(QString roomId_ = QString(), - JoinState joinState_ = JoinState::Join, - const QJsonObject& room_ = QJsonObject()); + SyncRoomData(const QString& roomId, JoinState joinState_, + const QJsonObject& room_); }; -} +} // namespace QMatrixClient Q_DECLARE_TYPEINFO(QMatrixClient::SyncRoomData, Q_MOVABLE_TYPE); namespace QMatrixClient @@ -63,12 +62,12 @@ namespace QMatrixClient // QVector cannot work with non-copiable objects, std::vector can. using SyncData = std::vector; - class ConnectionData; class SyncJob: public BaseJob { public: - SyncJob(ConnectionData* connection, QString since = {}, QString filter = {}, - int timeout = -1, QString presence = {}); + explicit SyncJob(const ConnectionData* connection, const QString& since = {}, + const QString& filter = {}, + int timeout = -1, const QString& presence = {}); virtual ~SyncJob(); SyncData& roomData(); @@ -81,4 +80,4 @@ namespace QMatrixClient class Private; Private* d; }; -} +} // namespace QMatrixClient -- cgit v1.2.3 From c25de4e19801c7931ce857c29a7a48be7f5c4dbe Mon Sep 17 00:00:00 2001 From: Kitsune Ral Date: Sat, 13 May 2017 16:00:26 +0900 Subject: More code cleanup and tweaks; fine-tuning logs; performance improvements After adding some profiling it became clear that to recalculate the room name and emit namesChanged() upon each member event is a waste, especially when there are thousands of those coming at initial sync (*cough* Matrix HQ room). So the room name is recalculated only once and unconditionally (in most cases this will boil down to checking whether name/canonicalAlias changed after processing the events batch), and namesChanged is only emitted once per batch, if any name or alias changed. --- jobs/syncjob.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'jobs/syncjob.h') diff --git a/jobs/syncjob.h b/jobs/syncjob.h index 21d3cfca..48be9423 100644 --- a/jobs/syncjob.h +++ b/jobs/syncjob.h @@ -70,7 +70,7 @@ namespace QMatrixClient int timeout = -1, const QString& presence = {}); virtual ~SyncJob(); - SyncData& roomData(); + SyncData&& takeRoomData(); QString nextBatch() const; protected: -- cgit v1.2.3