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. --- room.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'room.cpp') diff --git a/room.cpp b/room.cpp index f13fae19..5159cafd 100644 --- a/room.cpp +++ b/room.cpp @@ -115,7 +115,7 @@ class Room::Private /** * Removes events from the passed container that are already in the timeline */ - void dropDuplicateEvents(Events& events) const; + void dropDuplicateEvents(Events* events) const; void setLastReadEvent(User* u, QString eventId); rev_iter_pair_t promoteReadMarker(User* u, rev_iter_t newMarker); @@ -510,7 +510,7 @@ QString Room::roomMembername(User *u) const return username % " (" % u->id() % ")"; } -QString Room::roomMembername(QString userId) const +QString Room::roomMembername(const QString& userId) const { return roomMembername(connection()->user(userId)); } @@ -577,15 +577,15 @@ void Room::Private::getPreviousContent(int limit) } } -void Room::Private::dropDuplicateEvents(Events& events) const +void Room::Private::dropDuplicateEvents(Events* events) const { // Collect all duplicate events at the end of the container auto dupsBegin = - std::stable_partition(events.begin(), events.end(), + std::stable_partition(events->begin(), events->end(), [&] (Event* e) { return !eventsIndex.contains(e->id()); }); // Dispose of those dups - std::for_each(dupsBegin, events.end(), [] (Event* e) { delete e; }); - events.erase(dupsBegin, events.end()); + std::for_each(dupsBegin, events->end(), [] (Event* e) { delete e; }); + events->erase(dupsBegin, events->end()); } Connection* Room::connection() const @@ -595,7 +595,7 @@ Connection* Room::connection() const void Room::addNewMessageEvents(Events events) { - d->dropDuplicateEvents(events); + d->dropDuplicateEvents(&events); if (events.empty()) return; emit aboutToAddNewMessages(events); @@ -640,7 +640,7 @@ void Room::doAddNewMessageEvents(const Events& events) void Room::addHistoricalMessageEvents(Events events) { - d->dropDuplicateEvents(events); + d->dropDuplicateEvents(&events); if (events.empty()) return; emit aboutToAddHistoricalMessages(events); -- cgit v1.2.3