Commit 13182409 authored by Ronan's avatar Ronan

fix(Core): do not use map[] to test presence of element, [] create an item if not exist

parent 43a62dc8
......@@ -106,12 +106,14 @@ shared_ptr<AbstractChatRoom> CorePrivate::createClientGroupChatRoom (const strin
void CorePrivate::insertChatRoom (const shared_ptr<AbstractChatRoom> &chatRoom) {
L_ASSERT(chatRoom);
L_ASSERT(!chatRoomsById[chatRoom->getChatRoomId()]
|| (chatRoomsById[chatRoom->getChatRoomId()] == chatRoom)
);
if (!chatRoomsById[chatRoom->getChatRoomId()]) {
const ChatRoomId &chatRoomId = chatRoom->getChatRoomId();
auto it = chatRoomsById.find(chatRoomId);
// Chat room not exist or yes but with the same pointer!
L_ASSERT(it == chatRoomsById.end() || it->second == chatRoom);
if (it == chatRoomsById.end()) {
chatRooms.push_back(chatRoom);
chatRoomsById[chatRoom->getChatRoomId()] = chatRoom;
chatRoomsById[chatRoomId] = chatRoom;
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment