[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:
@@ -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();
|
||||||
|
|||||||
Reference in New Issue
Block a user