From 13182409bff36ce0325d0c6506e4212ee712f9b6 Mon Sep 17 00:00:00 2001 From: Ronan Abhamon Date: Tue, 20 Feb 2018 14:15:47 +0100 Subject: [PATCH] fix(Core): do not use map[] to test presence of element, [] create an item if not exist --- src/core/core-chat-room.cpp | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/core/core-chat-room.cpp b/src/core/core-chat-room.cpp index e9bc24996..8e8eeed9d 100644 --- a/src/core/core-chat-room.cpp +++ b/src/core/core-chat-room.cpp @@ -106,12 +106,14 @@ shared_ptr CorePrivate::createClientGroupChatRoom (const strin void CorePrivate::insertChatRoom (const shared_ptr &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; } }