diff options
author | Alexey Rusakov <Kitsune-Ral@users.sf.net> | 2021-07-14 19:54:31 +0200 |
---|---|---|
committer | Alexey Rusakov <Kitsune-Ral@users.sf.net> | 2021-07-14 19:54:31 +0200 |
commit | 5a200039d6a34815b29c4a918bca8fa451c61f45 (patch) | |
tree | 7a25fcf389af44c5380d73507ef4e4a2d25c5149 /lib | |
parent | 8dcb1868adc022efe3fde1fdb99fef2b6634c82c (diff) | |
download | libquotient-5a200039d6a34815b29c4a918bca8fa451c61f45.tar.gz libquotient-5a200039d6a34815b29c4a918bca8fa451c61f45.zip |
SyncData::parseJson(): further minor optimisation
Just to align with the similar changes coming in 0.7
Diffstat (limited to 'lib')
-rw-r--r-- | lib/syncdata.cpp | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/lib/syncdata.cpp b/lib/syncdata.cpp index d0827ea4..64aa65fd 100644 --- a/lib/syncdata.cpp +++ b/lib/syncdata.cpp @@ -186,10 +186,15 @@ void SyncData::parseJson(const QJsonObject& json, const QString& baseDir) deviceOneTimeKeysCount_); auto rooms = json.value("rooms"_ls).toObject(); - JoinStates::Int ii = 1; // ii is used to make a JoinState value auto totalRooms = 0; auto totalEvents = 0; - for (size_t i = 0; i < JoinStateStrings.size(); ++i, ii <<= 1) { + // The first comparison shortcuts the loop when not all states are there + // in the response (anything except "join" is only occasional, and "join" + // intentionally comes first in the enum). + for (size_t i = 0; int(i) < rooms.size() && i < JoinStateStrings.size(); + ++i) { + // This assumes that JoinState values go over powers of 2: 1,2,4,... + const auto joinState = JoinState(1U << i); const auto rs = rooms.value(JoinStateStrings[i]).toObject(); // We have a Qt container on the right and an STL one on the left roomData.reserve(roomData.size() + static_cast<size_t>(rs.size())); @@ -202,7 +207,7 @@ void SyncData::parseJson(const QJsonObject& json, const QString& baseDir) unresolvedRoomIds.push_back(roomIt.key()); continue; } - roomData.emplace_back(roomIt.key(), JoinState(ii), roomJson); + roomData.emplace_back(roomIt.key(), joinState, roomJson); const auto& r = roomData.back(); totalEvents += r.state.size() + r.ephemeral.size() + r.accountData.size() + r.timeline.size(); |