From 59e6b15f513cc998ce13e9e49e2a6a3ace445ebb Mon Sep 17 00:00:00 2001 From: George Hazan Date: Thu, 15 Mar 2018 21:05:06 +0300 Subject: LIST<> iterators: - new method LIST::removeItem added to save a pointer to removed record; - code cleaning related to the fact that LIST::remove() shall be the last operation inside an iterator, because otherwise the reference to it will point to a record next to deleted one; - a few remaining cycles converted to iterators --- protocols/MSN/src/msn_avatar.cpp | 7 +++---- protocols/MSN/src/msn_chat.cpp | 25 +++++++++++++------------ protocols/MSN/src/msn_srv.cpp | 2 +- protocols/MSN/src/msn_threads.cpp | 3 +-- 4 files changed, 18 insertions(+), 19 deletions(-) (limited to 'protocols/MSN/src') diff --git a/protocols/MSN/src/msn_avatar.cpp b/protocols/MSN/src/msn_avatar.cpp index cf520027a7..b2f1f36cb9 100644 --- a/protocols/MSN/src/msn_avatar.cpp +++ b/protocols/MSN/src/msn_avatar.cpp @@ -121,8 +121,7 @@ void __cdecl CMsnProto::MSN_AvatarsThread(void*) } mir_cslock lck(csAvatarQueue); - while (lsAvatarQueue.getCount() > 0) { - delete lsAvatarQueue[0]; - lsAvatarQueue.remove(0); - } + for (auto &it : lsAvatarQueue) + delete it; + lsAvatarQueue.destroy(); } diff --git a/protocols/MSN/src/msn_chat.cpp b/protocols/MSN/src/msn_chat.cpp index fe9b611941..804cb64951 100644 --- a/protocols/MSN/src/msn_chat.cpp +++ b/protocols/MSN/src/msn_chat.cpp @@ -118,12 +118,12 @@ void CMsnProto::MSN_ChatStart(ezxml_t xmli) } // Remove contacts not on list (not tagged) - for (int j = 0; j < info->mJoinedContacts.getCount(); j++) { - if (!info->mJoinedContacts[j]->btag) { - info->mJoinedContacts.remove(j); - j--; - } - else info->mJoinedContacts[j]->btag = 0; + auto T = info->mJoinedContacts.rev_iter(); + for (auto &it : T) { + if (!it->btag) + info->mJoinedContacts.remove(T.indexOf(&it)); + else + it->btag = 0; } } @@ -458,12 +458,13 @@ int CMsnProto::MSN_GCEventHook(WPARAM, LPARAM lParam) case GC_SESSION_TERMINATE: { GCThreadData* thread = MSN_GetThreadByChatId(gch->ptszID); - if (thread != nullptr) { - m_arGCThreads.remove(thread); - for (auto &it : thread->mJoinedContacts) - delete it; - delete thread; - } + if (thread == nullptr) + break; + + m_arGCThreads.remove(thread); + for (auto &it : thread->mJoinedContacts) + delete it; + delete thread; } break; diff --git a/protocols/MSN/src/msn_srv.cpp b/protocols/MSN/src/msn_srv.cpp index cc9ff30f2b..b61fddd873 100644 --- a/protocols/MSN/src/msn_srv.cpp +++ b/protocols/MSN/src/msn_srv.cpp @@ -48,7 +48,7 @@ void CMsnProto::MSN_DeleteGroup(const char* pId) { int i = m_arGroups.getIndex((ServerGroupItem*)&pId); if (i > -1) { - ServerGroupItem* p = m_arGroups[i]; + ServerGroupItem *p = m_arGroups[i]; mir_free(p->id); mir_free(p->name); mir_free(p); diff --git a/protocols/MSN/src/msn_threads.cpp b/protocols/MSN/src/msn_threads.cpp index c75e4b643c..4f762b02e8 100644 --- a/protocols/MSN/src/msn_threads.cpp +++ b/protocols/MSN/src/msn_threads.cpp @@ -453,9 +453,8 @@ void __cdecl CMsnProto::ThreadStub(void* arg) debugLogA("Leaving thread %08X (%08X)", GetCurrentThreadId(), info->mFunc); { mir_cslock lck(m_csThreads); - m_arThreads.LIST::remove(info); + m_arThreads.remove(info); } - delete info; } void ThreadData::startThread(MsnThreadFunc parFunc, CMsnProto *prt) -- cgit v1.2.3