aboutsummaryrefslogtreecommitdiff
path: root/lib/user.cpp
diff options
context:
space:
mode:
authorKitsune Ral <Kitsune-Ral@users.sf.net>2018-11-03 20:10:22 +0900
committerKitsune Ral <Kitsune-Ral@users.sf.net>2018-11-03 20:10:22 +0900
commit00f2f9f376a046717bed6818410610b6cc52dd9a (patch)
treeb585785b9c0874059bd70a2847aa4e91cf565397 /lib/user.cpp
parent7c7ce3d468af242364efb53e77ed12047b6a5382 (diff)
downloadlibquotient-00f2f9f376a046717bed6818410610b6cc52dd9a.tar.gz
libquotient-00f2f9f376a046717bed6818410610b6cc52dd9a.zip
User::displayname(): avoid calling nameForRoom twice
nameForRoom() is O(n) in this context (n - number of names of a given user).
Diffstat (limited to 'lib/user.cpp')
-rw-r--r--lib/user.cpp10
1 files changed, 6 insertions, 4 deletions
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 % ')';
}