From 00f2f9f376a046717bed6818410610b6cc52dd9a Mon Sep 17 00:00:00 2001 From: Kitsune Ral Date: Sat, 3 Nov 2018 20:10:22 +0900 Subject: User::displayname(): avoid calling nameForRoom twice nameForRoom() is O(n) in this context (n - number of names of a given user). --- lib/user.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'lib/user.cpp') diff --git a/lib/user.cpp b/lib/user.cpp index eec08ad9..bfd23ae2 100644 --- a/lib/user.cpp +++ b/lib/user.cpp @@ -321,14 +321,16 @@ void User::Private::setAvatarOnServer(QString contentUri, User* q) QString User::displayname(const Room* room) const { - auto name = d->nameForRoom(room); - return name.isEmpty() ? d->userId : - room ? room->roomMembername(this) : name; + if (room) + return room->roomMembername(this); + + const auto name = d->nameForRoom(nullptr); + return name.isEmpty() ? d->userId : name; } QString User::fullName(const Room* room) const { - auto name = d->nameForRoom(room); + const auto name = d->nameForRoom(room); return name.isEmpty() ? d->userId : name % " (" % d->userId % ')'; } -- cgit v1.2.3