[clazy] Fix allocating an unneeded temporary container

Instead of creating a new container and iterate over it, we wrap the
loop in a lambda and use the lambda for the two initial container.
This commit is contained in:
Carl Schwan
2020-11-19 09:40:38 +01:00
parent d5379f86c1
commit 7b30c199a4

View File

@@ -58,12 +58,16 @@ void RoomListModel::setConnection(Connection *connection)
connect(connection, &Connection::leftRoom, this, &RoomListModel::updateRoom); connect(connection, &Connection::leftRoom, this, &RoomListModel::updateRoom);
connect(connection, &Connection::aboutToDeleteRoom, this, &RoomListModel::deleteRoom); connect(connection, &Connection::aboutToDeleteRoom, this, &RoomListModel::deleteRoom);
connect(connection, &Connection::directChatsListChanged, this, [=](Quotient::DirectChatsMap additions, Quotient::DirectChatsMap removals) { connect(connection, &Connection::directChatsListChanged, this, [=](Quotient::DirectChatsMap additions, Quotient::DirectChatsMap removals) {
const auto values = additions.values() + removals.values(); auto refreshRooms = [this, &connection](Quotient::DirectChatsMap rooms) {
for (const QString &roomID : values) { for (const QString &roomID : qAsConst(rooms)) {
auto room = connection->room(roomID); auto room = connection->room(roomID);
if (room) if (room)
refresh(static_cast<NeoChatRoom *>(room)); refresh(static_cast<NeoChatRoom *>(room));
} }
};
refreshRooms(additions);
refreshRooms(removals);
}); });
doResetModel(); doResetModel();
@@ -75,8 +79,9 @@ void RoomListModel::doResetModel()
{ {
beginResetModel(); beginResetModel();
m_rooms.clear(); m_rooms.clear();
for (auto r : m_connection->allRooms()) { const auto rooms = m_connection->allRooms();
doAddRoom(r); for (const auto &room : rooms) {
doAddRoom(room);
} }
endResetModel(); endResetModel();
refreshNotificationCount(); refreshNotificationCount();