diff options
author | George Hazan <ghazan@miranda.im> | 2018-03-15 21:05:06 +0300 |
---|---|---|
committer | George Hazan <ghazan@miranda.im> | 2018-03-15 21:05:06 +0300 |
commit | 59e6b15f513cc998ce13e9e49e2a6a3ace445ebb (patch) | |
tree | af52b73a17039ed1fbe398ba9f488c26a7071257 | |
parent | bdaa5cf8b48515af2ac39f3f3245dd1183cbad52 (diff) |
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
41 files changed, 176 insertions, 192 deletions
diff --git a/include/m_system_cpp.h b/include/m_system_cpp.h index 729ddcb414..b262254dfb 100644 --- a/include/m_system_cpp.h +++ b/include/m_system_cpp.h @@ -233,6 +233,13 @@ template<class T> struct LIST __inline int insert(T *p) { return List_InsertPtr((SortedList*)this, p); }
__inline int remove(T *p) { return List_RemovePtr((SortedList*)this, p); }
+ __inline T* removeItem(T **p)
+ {
+ T *savePtr = *p;
+ List_Remove((SortedList*)this, int(p - items));
+ return savePtr;
+ }
+
__inline void put(int idx, T *p) { items[idx] = p; }
__inline T** begin() const { return items; }
diff --git a/plugins/Clist_modern/src/modern_skinengine.cpp b/plugins/Clist_modern/src/modern_skinengine.cpp index 986de4cac7..d51deeebf1 100644 --- a/plugins/Clist_modern/src/modern_skinengine.cpp +++ b/plugins/Clist_modern/src/modern_skinengine.cpp @@ -527,21 +527,20 @@ int ske_ReleaseBufferDC(HDC hDC, int keepTime) //Try to find DC in buffer list - set flag to be release after time; mir_cslock lck(BufferListCS); - for (int i = 0; i < BufferList.getCount(); i++) { - DCBUFFER *pBuf = BufferList[i]; - if (pBuf) { - if (hDC != nullptr && pBuf->hDC == hDC) { - pBuf->dwDestroyAfterTime = dwCurrentTime + keepTime; + auto T = BufferList.rev_iter(); + for (auto &it : T) { + if (it) { + if (hDC != nullptr && it->hDC == hDC) { + it->dwDestroyAfterTime = dwCurrentTime + keepTime; break; } - if ((pBuf->dwDestroyAfterTime && pBuf->dwDestroyAfterTime < dwCurrentTime) || keepTime == -1) { - SelectObject(pBuf->hDC, pBuf->oldBitmap); - DeleteObject(pBuf->hBitmap); - DeleteDC(pBuf->hDC); - mir_free(pBuf); - BufferList.remove(i); - i--; + if ((it->dwDestroyAfterTime && it->dwDestroyAfterTime < dwCurrentTime) || keepTime == -1) { + SelectObject(it->hDC, it->oldBitmap); + DeleteObject(it->hBitmap); + DeleteDC(it->hDC); + mir_free(it); + BufferList.remove(T.indexOf(&it)); } } } diff --git a/plugins/Clist_modern/src/modern_xptheme.cpp b/plugins/Clist_modern/src/modern_xptheme.cpp index 6122fa21f6..bff9e8a7fb 100644 --- a/plugins/Clist_modern/src/modern_xptheme.cpp +++ b/plugins/Clist_modern/src/modern_xptheme.cpp @@ -72,14 +72,12 @@ void xpt_FreeThemeHandle(XPTHANDLE xptHandle) void xpt_FreeThemeForWindow(HWND hwnd)
{
mir_cslock lck(xptCS);
- for (int i = 0; i < xptObjectList.getCount();) {
- XPTObject& xptObject = xptObjectList[i];
- if (xptObject.hOwnerWindow == hwnd) {
- _sttXptCloseThemeData(&xptObject);
- xptObjectList.remove(i);
+ auto T = xptObjectList.rev_iter();
+ for (auto &xptObject : T)
+ if (xptObject->hOwnerWindow == hwnd) {
+ _sttXptCloseThemeData(xptObject);
+ xptObjectList.remove(T.indexOf(&xptObject));
}
- else i++;
- }
}
void xpt_OnWM_THEMECHANGED()
diff --git a/plugins/NewXstatusNotify/src/xstatus.cpp b/plugins/NewXstatusNotify/src/xstatus.cpp index c15cf4e746..0267704979 100644 --- a/plugins/NewXstatusNotify/src/xstatus.cpp +++ b/plugins/NewXstatusNotify/src/xstatus.cpp @@ -46,8 +46,8 @@ void RemoveLoggedEventsXStatus(MCONTACT hContact) for (auto &it : T)
if (it->hContact == hContact) {
db_event_delete(it->hContact, it->hDBEvent);
- eventListXStatus.remove(T.indexOf(&it));
mir_free(it);
+ eventListXStatus.remove(T.indexOf(&it));
}
}
@@ -57,8 +57,8 @@ void RemoveLoggedEventsStatus(MCONTACT hContact) for (auto &it : T)
if (it->hContact == hContact) {
db_event_delete(it->hContact, it->hDBEvent);
- eventListStatus.remove(T.indexOf(&it));
mir_free(it);
+ eventListStatus.remove(T.indexOf(&it));
}
}
@@ -68,8 +68,8 @@ void RemoveLoggedEventsSMsg(MCONTACT hContact) for (auto &it : T)
if (it->hContact == hContact) {
db_event_delete(it->hContact, it->hDBEvent);
- eventListSMsg.remove(T.indexOf(&it));
mir_free(it);
+ eventListSMsg.remove(T.indexOf(&it));
}
}
diff --git a/plugins/Popup/src/popup_thread.cpp b/plugins/Popup/src/popup_thread.cpp index 75e306a0b8..5caede1cf1 100644 --- a/plugins/Popup/src/popup_thread.cpp +++ b/plugins/Popup/src/popup_thread.cpp @@ -179,9 +179,12 @@ static LRESULT CALLBACK PopupThreadManagerWndProc(HWND hwnd, UINT message, WPARA break;
case UTM_REMOVE_WINDOW:
- for (int i = popupList.getCount() - 1; i >= 0; i--)
- if (popupList[i] == wnd)
- popupList.remove(i);
+ {
+ auto T = popupList.rev_iter();
+ for (auto &it : T)
+ if (it == wnd)
+ popupList.remove(T.indexOf(&it));
+ }
RepositionPopups();
--nPopups;
diff --git a/plugins/Popup/src/services.cpp b/plugins/Popup/src/services.cpp index b1d659d241..e6f09614cc 100644 --- a/plugins/Popup/src/services.cpp +++ b/plugins/Popup/src/services.cpp @@ -419,7 +419,7 @@ INT_PTR Popup_UnregisterPopupClass(WPARAM, LPARAM lParam) for (auto &it : gTreeData)
if (it == ptd) {
- gTreeData.remove(it);
+ gTreeData.removeItem(&it);
FreePopupClass(ptd);
return 0;
}
diff --git a/plugins/QuickContacts/src/quickcontacts.cpp b/plugins/QuickContacts/src/quickcontacts.cpp index b530245b6b..d0c720b2e7 100644 --- a/plugins/QuickContacts/src/quickcontacts.cpp +++ b/plugins/QuickContacts/src/quickcontacts.cpp @@ -310,10 +310,9 @@ int GetStatus(MCONTACT hContact, char *proto = nullptr) void FreeContacts()
{
- for (int i = contacts.getCount() - 1; i >= 0; i--) {
- delete contacts[i];
- contacts.remove(i);
- }
+ for (auto &it : contacts)
+ delete it;
+ contacts.destroy();
}
diff --git a/plugins/SmileyAdd/src/download.cpp b/plugins/SmileyAdd/src/download.cpp index 7633dffab0..306b980276 100644 --- a/plugins/SmileyAdd/src/download.cpp +++ b/plugins/SmileyAdd/src/download.cpp @@ -136,7 +136,10 @@ void __cdecl SmileyDownloadThread(void*) WaitForSingleObject(g_hDlMutex, 3000);
CMStringW fname(dlQueue[0].fname);
- if (dlQueue[0].needext) { fname += GetImageExt(fname); needext = true; }
+ if (dlQueue[0].needext) {
+ fname += GetImageExt(fname);
+ needext = true;
+ }
_wrename(dlQueue[0].fname.c_str(), fname.c_str());
}
else WaitForSingleObject(g_hDlMutex, 3000);
diff --git a/plugins/SmileyAdd/src/smileys.cpp b/plugins/SmileyAdd/src/smileys.cpp index 16de9ebdf9..5b07d56bd4 100644 --- a/plugins/SmileyAdd/src/smileys.cpp +++ b/plugins/SmileyAdd/src/smileys.cpp @@ -762,9 +762,9 @@ void SmileyCategoryListType::DeleteAccountAsCategory(PROTOACCOUNT *acc) }
}
- for (int i = 0; i < m_SmileyCategories.getCount(); i++) {
- if (tname.CompareNoCase(m_SmileyCategories[i].GetName()) == 0) {
- m_SmileyCategories.remove(i);
+ for (auto &it : m_SmileyCategories) {
+ if (tname.CompareNoCase(it->GetName()) == 0) {
+ m_SmileyCategories.removeItem(&it);
break;
}
}
diff --git a/plugins/StatusManager/src/main.cpp b/plugins/StatusManager/src/main.cpp index 651123f71c..5d5db295e3 100644 --- a/plugins/StatusManager/src/main.cpp +++ b/plugins/StatusManager/src/main.cpp @@ -105,7 +105,7 @@ int OnAccChanged(WPARAM wParam, LPARAM lParam) case PRAC_REMOVED: for (auto &it : protoList) { if (!mir_strcmp(it->m_szName, pa->szModuleName)) { - protoList.remove(it); + protoList.removeItem(&it); break; } } diff --git a/plugins/UserInfoEx/src/mir_contactqueue.cpp b/plugins/UserInfoEx/src/mir_contactqueue.cpp index 9ba36425ad..f74a5c1795 100644 --- a/plugins/UserInfoEx/src/mir_contactqueue.cpp +++ b/plugins/UserInfoEx/src/mir_contactqueue.cpp @@ -86,8 +86,8 @@ void CContactQueue::RemoveAll(MCONTACT hContact) auto T = _queue.rev_iter();
for (auto &qi : T) {
if (qi->hContact == hContact) {
- _queue.remove(T.indexOf(&qi));
mir_free(qi);
+ _queue.remove(T.indexOf(&qi));
}
}
}
@@ -102,8 +102,8 @@ void CContactQueue::RemoveAllConsiderParam(MCONTACT hContact, PVOID param) auto T = _queue.rev_iter();
for (auto &qi : T)
if (qi->hContact == hContact && qi->param == param) {
- _queue.remove(T.indexOf(&qi));
mir_free(qi);
+ _queue.remove(T.indexOf(&qi));
}
}
diff --git a/protocols/Discord/src/dispatch.cpp b/protocols/Discord/src/dispatch.cpp index 33cf2fe556..53c561aaf2 100644 --- a/protocols/Discord/src/dispatch.cpp +++ b/protocols/Discord/src/dispatch.cpp @@ -164,10 +164,10 @@ void CDiscordProto::OnCommandFriendRemoved(const JSONNode &pRoot) SnowFlake id = ::getId(pRoot["id"]); CDiscordUser *pUser = FindUser(id); if (pUser != nullptr) { - if (pUser->hContact) { + if (pUser->hContact) if (pUser->bIsPrivate) db_delete_contact(pUser->hContact); - } + arUsers.remove(pUser); } } diff --git a/protocols/IRCG/src/commandmonitor.cpp b/protocols/IRCG/src/commandmonitor.cpp index 72db70fc6f..05ca521f17 100644 --- a/protocols/IRCG/src/commandmonitor.cpp +++ b/protocols/IRCG/src/commandmonitor.cpp @@ -2081,9 +2081,10 @@ bool CIrcProto::OnIrc_USERHOST_REPLY(const CIrcMessage *pmsg) setWString(hContact, "Nick", nick);
// If user found, remove from checklist
- for (int i = 0; i < checklist.getCount(); i++)
- if (!mir_wstrcmpi(checklist[i], nick))
- checklist.remove(i);
+ auto T = checklist.rev_iter();
+ for (auto &it : T)
+ if (!mir_wstrcmpi(it->GetString(), nick))
+ checklist.remove(T.indexOf(&it));
}
}
break;
diff --git a/protocols/IRCG/src/irclib.cpp b/protocols/IRCG/src/irclib.cpp index 681e1b19ba..28db677271 100644 --- a/protocols/IRCG/src/irclib.cpp +++ b/protocols/IRCG/src/irclib.cpp @@ -470,7 +470,7 @@ void CIrcProto::RemoveDCCSession(MCONTACT hContact) for (auto &it : m_dcc_chats) if (it->di->hContact == hContact) { - m_dcc_chats.remove(it); + m_dcc_chats.removeItem(&it); break; } } @@ -481,7 +481,7 @@ void CIrcProto::RemoveDCCSession(DCCINFO *pdci) for (auto &it : m_dcc_xfers) { if (it->di == pdci) { - m_dcc_xfers.remove(it); + m_dcc_xfers.removeItem(&it); break; } } diff --git a/protocols/IcqOscarJ/src/cookies.cpp b/protocols/IcqOscarJ/src/cookies.cpp index a517f93923..0eb4dcc2fd 100644 --- a/protocols/IcqOscarJ/src/cookies.cpp +++ b/protocols/IcqOscarJ/src/cookies.cpp @@ -182,7 +182,7 @@ void CIcqProto::FreeCookieByData(BYTE bType, void *pvExtra) for (auto &it : cookies) {
if (bType == it->bType && pvExtra == it->pvExtra) {
// Cookie found, remove from list
- cookies.remove(it);
+ cookies.removeItem(&it);
break;
}
}
diff --git a/protocols/IcqOscarJ/src/icq_avatar.cpp b/protocols/IcqOscarJ/src/icq_avatar.cpp index 28ef778680..c3d6b5792f 100644 --- a/protocols/IcqOscarJ/src/icq_avatar.cpp +++ b/protocols/IcqOscarJ/src/icq_avatar.cpp @@ -187,19 +187,18 @@ void CIcqProto::StartAvatarThread(HNETLIBCONN hConn, char *cookie, size_t cookie // check if any upload request are waiting in the queue
int bYet = 0;
- for (int i = 0; i < m_arAvatars.getCount();) {
- avatars_request *ar = m_arAvatars[i];
- if (ar->type == ART_UPLOAD) { // we found it, return error
+ auto T = m_arAvatars.rev_iter();
+ for (auto &it : T) {
+ if (it->type == ART_UPLOAD) { // we found it, return error
if (!bYet) {
icq_LogMessage(LOG_WARNING, LPGEN("Error uploading avatar to server, server temporarily unavailable."));
bYet = 1;
}
// remove upload request from queue
- m_arAvatars.remove(i);
- delete ar;
+ delete it;
+ m_arAvatars.remove(T.indexOf(&it));
}
- else i++;
}
SAFE_FREE((void**)&cookie);
@@ -489,11 +488,10 @@ void CIcqProto::handleAvatarContactHash(DWORD dwUIN, char *szUID, MCONTACT hCont if (bJob == TRUE) { // Remove possible block - hash changed, try again.
mir_cslock l(m_avatarsMutex);
- for (int i = 0; i < m_arAvatars.getCount(); i++) {
- avatars_request *ar = m_arAvatars[i];
- if (ar->hContact == hContact && ar->type == ART_BLOCK) { // found one, remove
- m_arAvatars.remove(i);
- delete ar;
+ for (auto &it : m_arAvatars) {
+ if (it->hContact == hContact && it->type == ART_BLOCK) { // found one, remove
+ delete it;
+ m_arAvatars.removeItem(&it);
break;
}
}
@@ -536,18 +534,17 @@ int CIcqProto::GetAvatarData(MCONTACT hContact, DWORD dwUin, const char *szUid, if (m_avatarsConnection && m_avatarsConnection->isReady()) { // check if we are ready
// check if requests for this user are not blocked
- for (int i = 0; i < m_arAvatars.getCount();) {
- avatars_request *ar = m_arAvatars[i];
+ auto T = m_arAvatars.rev_iter();
+ for (auto &ar : T) {
if (ar->hContact == hContact && ar->type == ART_BLOCK) { // found a block item
if (GetTickCount() > ar->timeOut) { // remove timeouted block
- m_arAvatars.remove(i);
delete ar;
+ m_arAvatars.remove(T.indexOf(&ar));
continue;
}
debugLogA("Avatars: Requests for %s avatar are blocked.", strUID(dwUin, pszUid));
return 0;
}
- i++;
}
mir_cslock l(m_avatarsConnection->getLock());
@@ -562,12 +559,12 @@ int CIcqProto::GetAvatarData(MCONTACT hContact, DWORD dwUin, const char *szUid, // we failed to send request, or avatar thread not ready
// check if any request for this user is not already in the queue
- for (int i = 0; i < m_arAvatars.getCount();) {
- avatars_request *ar = m_arAvatars[i];
+ auto T = m_arAvatars.rev_iter();
+ for (auto &ar : T) {
if (ar->hContact == hContact) { // we found it, return error
if (ar->type == ART_BLOCK && GetTickCount() > ar->timeOut) { // remove timeouted block
- m_arAvatars.remove(i);
delete ar;
+ m_arAvatars.remove(T.indexOf(&ar));
continue;
}
alck.unlock();
@@ -577,7 +574,6 @@ int CIcqProto::GetAvatarData(MCONTACT hContact, DWORD dwUin, const char *szUid, requestAvatarConnection();
return 0;
}
- i++;
}
// add request to queue, processed after successful login
@@ -728,12 +724,11 @@ void avatars_server_connection::shutdownConnection() DWORD avatars_server_connection::sendGetAvatarRequest(MCONTACT hContact, DWORD dwUin, char *szUid, const BYTE *hash, size_t hashlen, const wchar_t *file)
{
- int i;
DWORD dwNow = GetTickCount();
mir_cslockfull alck(ppro->m_avatarsMutex);
- for (i = 0; i < runCount;) { // look for timeouted requests
+ for (int i = 0; i < runCount;) { // look for timeouted requests
if (runTime[i] < dwNow) { // found outdated, remove
runContact[i] = runContact[runCount - 1];
runTime[i] = runTime[runCount - 1];
@@ -742,7 +737,7 @@ DWORD avatars_server_connection::sendGetAvatarRequest(MCONTACT hContact, DWORD d else i++;
}
- for (i = 0; i < runCount; i++) {
+ for (int i = 0; i < runCount; i++) {
if (runContact[i] == hContact) {
ppro->debugLogA("Ignoring duplicate get %s image request.", strUID(dwUin, szUid));
return -1; // Success: request ignored
@@ -849,11 +844,11 @@ void avatars_server_connection::checkRequestQueue() }
if (pRequest->type == ART_BLOCK) { // block contact processing
- for (int i = 0; i < ppro->m_arAvatars.getCount(); i++) {
- avatars_request *ar = ppro->m_arAvatars[i];
+ auto T = ppro->m_arAvatars.rev_iter();
+ for (auto &ar : T) {
if (GetTickCount() > ar->timeOut) { // expired contact block, remove
- ppro->m_arAvatars.remove(i);
delete ar;
+ ppro->m_arAvatars.remove(T.indexOf(&ar));
}
}
return; // end processing
diff --git a/protocols/IcqOscarJ/src/icq_direct.cpp b/protocols/IcqOscarJ/src/icq_direct.cpp index 3ecbbe8d92..9872dbd9d6 100644 --- a/protocols/IcqOscarJ/src/icq_direct.cpp +++ b/protocols/IcqOscarJ/src/icq_direct.cpp @@ -76,10 +76,8 @@ filetransfer* CIcqProto::FindExpectedFileRecv(DWORD dwUin, DWORD dwTotalSize) mir_cslock l(expectedFileRecvMutex);
for (auto &it : expectedFileRecvs)
- if (it->dwUin == dwUin && it->dwTotalSize == dwTotalSize) {
- expectedFileRecvs.remove(it);
- return it;
- }
+ if (it->dwUin == dwUin && it->dwTotalSize == dwTotalSize)
+ return expectedFileRecvs.removeItem(&it);
return nullptr;
}
diff --git a/protocols/IcqOscarJ/src/icq_rates.cpp b/protocols/IcqOscarJ/src/icq_rates.cpp index b2d3ee2823..e2dc3d569f 100644 --- a/protocols/IcqOscarJ/src/icq_rates.cpp +++ b/protocols/IcqOscarJ/src/icq_rates.cpp @@ -386,16 +386,16 @@ void rates_queue::putItem(rates_queue_item *pItem, int nMinDelay) ppro->debugLogA("Rates: Delaying %s.", szDescr);
{
mir_cslock l(csLists);
- if (lstPending.getCount()) {
- for (int i = 0; i < lstPending.getCount(); i++) {
- if (lstPending[i]->isEqual(pItem)) {
- if (duplicates == 1) // keep existing, ignore new
- return;
-
- if (duplicates == -1) { // discard existing, append new item
- delete lstPending[i];
- lstPending.remove(i);
- }
+
+ auto T = lstPending.rev_iter();
+ for (auto &it : T) {
+ if (it->isEqual(pItem)) {
+ if (duplicates == 1) // keep existing, ignore new
+ return;
+
+ if (duplicates == -1) { // discard existing, append new item
+ delete it;
+ lstPending.remove(T.indexOf(&it));
}
}
}
diff --git a/protocols/IcqOscarJ/src/utilities.cpp b/protocols/IcqOscarJ/src/utilities.cpp index 97253e2cc1..e7af9c8a33 100644 --- a/protocols/IcqOscarJ/src/utilities.cpp +++ b/protocols/IcqOscarJ/src/utilities.cpp @@ -388,10 +388,10 @@ void CIcqProto::DeleteFromContactsCache(MCONTACT hContact) for (auto &it : contactsCache) {
if (it->hContact == hContact) {
- contactsCache.remove(it);
// Release memory
SAFE_FREE((void**)&it->szUid);
SAFE_FREE((void**)&it);
+ contactsCache.removeItem(&it);
break;
}
}
diff --git a/protocols/JabberG/src/jabber_frame.cpp b/protocols/JabberG/src/jabber_frame.cpp index 170147508c..9253442816 100644 --- a/protocols/JabberG/src/jabber_frame.cpp +++ b/protocols/JabberG/src/jabber_frame.cpp @@ -474,15 +474,14 @@ void CJabberInfoFrame::RemoveInfoItem(char *pszName) {
bool bUpdate = false;
size_t length = mir_strlen(pszName);
- for (int i = 0; i < m_pItems.getCount(); i++) {
- auto &p = m_pItems[i];
- if (!strncmp(p.m_pszName, pszName, length)) {
- if (!p.m_bShow)
+ auto T = m_pItems.rev_iter();
+ for (auto &p : T) {
+ if (!strncmp(p->m_pszName, pszName, length)) {
+ if (!p->m_bShow)
--m_hiddenItemCount;
- RemoveTooltip(p.m_tooltipId);
- m_pItems.remove(i);
+ RemoveTooltip(p->m_tooltipId);
+ m_pItems.remove(T.indexOf(&p));
bUpdate = true;
- --i;
}
}
diff --git a/protocols/JabberG/src/jabber_iq.cpp b/protocols/JabberG/src/jabber_iq.cpp index 6474d0b5b9..2a0c5de4f0 100644 --- a/protocols/JabberG/src/jabber_iq.cpp +++ b/protocols/JabberG/src/jabber_iq.cpp @@ -143,7 +143,7 @@ void CJabberIqManager::ExpirerThread() Thread_SetName("Jabber: ExpirerThread");
while (!m_bExpirerThreadShutdownRequest) {
- CJabberIqInfo *pInfo = DetouchExpired();
+ CJabberIqInfo *pInfo = DetachExpired();
if (!pInfo) {
for (int i=0; !m_bExpirerThreadShutdownRequest && (i < 10); i++)
Sleep(50);
@@ -181,14 +181,14 @@ void CJabberIqManager::ExpireInfo(CJabberIqInfo *pInfo) void CJabberIqManager::ExpireIq(int nIqId)
{
- while (CJabberIqInfo *pInfo = DetouchInfo(nIqId))
+ while (CJabberIqInfo *pInfo = DetachInfo(nIqId))
ExpireInfo(pInfo);
}
bool CJabberIqManager::ExpireByUserData(void *pUserData)
{
bool bRet = false;
- while (CJabberIqInfo *pInfo = DetouchInfo(pUserData)) {
+ while (CJabberIqInfo *pInfo = DetachInfo(pUserData)) {
ExpireInfo(pInfo);
bRet = true;
}
@@ -197,7 +197,7 @@ bool CJabberIqManager::ExpireByUserData(void *pUserData) void CJabberIqManager::ExpireAll()
{
- while (CJabberIqInfo *pInfo = DetouchInfo())
+ while (CJabberIqInfo *pInfo = DetachInfo())
ExpireInfo(pInfo);
}
@@ -226,9 +226,9 @@ bool CJabberIqManager::DeleteHandler(CJabberIqInfo *pInfo) // returns TRUE when pInfo found, or FALSE otherwise
mir_cslockfull lck(m_cs);
- for (int i = 0; i < m_arIqs.getCount(); i++) {
- if (m_arIqs[i] == pInfo) {
- m_arIqs.remove(i);
+ for (auto &it : m_arIqs) {
+ if (it == pInfo) {
+ m_arIqs.removeItem(&it);
lck.unlock();
ExpireInfo(pInfo); // must expire it to allow the handler to free m_pUserData if necessary
return true;
@@ -255,7 +255,7 @@ bool CJabberIqManager::HandleIq(int nIqId, HXML pNode) else
return false;
- CJabberIqInfo *pInfo = DetouchInfo(nIqId);
+ CJabberIqInfo *pInfo = DetachInfo(nIqId);
if (pInfo == nullptr)
return false;
@@ -285,7 +285,7 @@ bool CJabberIqManager::HandleIq(int nIqId, HXML pNode) (ppro->*(pInfo->m_pHandler))(pNode, pInfo);
delete pInfo;
}
- while ((pInfo = DetouchInfo(nIqId)) != nullptr);
+ while ((pInfo = DetachInfo(nIqId)) != nullptr);
return true;
}
@@ -344,7 +344,7 @@ bool CJabberIqManager::HandleIqPermanent(HXML pNode) return false;
}
-CJabberIqInfo* CJabberIqManager::DetouchInfo()
+CJabberIqInfo* CJabberIqManager::DetachInfo()
{
mir_cslock lck(m_cs);
@@ -354,48 +354,37 @@ CJabberIqInfo* CJabberIqManager::DetouchInfo() return pInfo;
}
-CJabberIqInfo* CJabberIqManager::DetouchInfo(int nIqId)
+CJabberIqInfo* CJabberIqManager::DetachInfo(int nIqId)
{
mir_cslock lck(m_cs);
- for (int i = 0; i < m_arIqs.getCount(); i++) {
- CJabberIqInfo *pInfo = m_arIqs[i];
- if (pInfo->m_nIqId == nIqId) {
- m_arIqs.remove(i);
- return pInfo;
- }
- }
+ for (auto &it : m_arIqs)
+ if (it->m_nIqId == nIqId)
+ return m_arIqs.removeItem(&it);
return nullptr;
}
-CJabberIqInfo* CJabberIqManager::DetouchInfo(void *pUserData)
+CJabberIqInfo* CJabberIqManager::DetachInfo(void *pUserData)
{
mir_cslock lck(m_cs);
- for (int i = 0; i < m_arIqs.getCount(); i++) {
- CJabberIqInfo *pInfo = m_arIqs[i];
- if (pInfo->m_pUserData == pUserData) {
- m_arIqs.remove(i);
- return pInfo;
- }
- }
+ for (auto &it : m_arIqs)
+ if (it->m_pUserData == pUserData)
+ return m_arIqs.removeItem(&it);
+
return nullptr;
}
-CJabberIqInfo* CJabberIqManager::DetouchExpired()
+CJabberIqInfo* CJabberIqManager::DetachExpired()
{
DWORD dwCurrentTime = GetTickCount();
mir_cslock lck(m_cs);
- for (int i = 0; i < m_arIqs.getCount(); i++) {
- CJabberIqInfo *pInfo = m_arIqs[i];
- if (dwCurrentTime - pInfo->m_dwRequestTime > pInfo->m_dwTimeout) {
- m_arIqs.remove(i);
- return pInfo;
- }
- }
+ for (auto &it : m_arIqs)
+ if (dwCurrentTime - it->m_dwRequestTime > it->m_dwTimeout)
+ return m_arIqs.removeItem(&it);
return nullptr;
}
diff --git a/protocols/JabberG/src/jabber_iq.h b/protocols/JabberG/src/jabber_iq.h index 7248e0606d..bc252f4119 100644 --- a/protocols/JabberG/src/jabber_iq.h +++ b/protocols/JabberG/src/jabber_iq.h @@ -150,10 +150,10 @@ protected: LIST<CJabberIqInfo> m_arIqs;
OBJLIST<CJabberIqPermanentInfo> m_arHandlers;
- CJabberIqInfo* DetouchInfo();
- CJabberIqInfo* DetouchInfo(int nIqId);
- CJabberIqInfo* DetouchInfo(void *pUserData);
- CJabberIqInfo* DetouchExpired();
+ CJabberIqInfo* DetachInfo();
+ CJabberIqInfo* DetachInfo(int nIqId);
+ CJabberIqInfo* DetachInfo(void *pUserData);
+ CJabberIqInfo* DetachExpired();
void ExpireInfo(CJabberIqInfo *pInfo);
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<ThreadData>::remove(info);
+ m_arThreads.remove(info);
}
- delete info;
}
void ThreadData::startThread(MsnThreadFunc parFunc, CMsnProto *prt)
diff --git a/protocols/Steam/src/steam_request.cpp b/protocols/Steam/src/steam_request.cpp index 51b09ecfc3..06e83c4c25 100644 --- a/protocols/Steam/src/steam_request.cpp +++ b/protocols/Steam/src/steam_request.cpp @@ -91,13 +91,11 @@ void CSteamProto::RequestQueueThread(void*) ProcessRequestQueue();
WaitForSingleObject(m_hRequestsQueueEvent, 1000);
} while (!m_isTerminated);
- {
- mir_cslock lock(m_requestQueueLock);
- for (int i = 0; i < m_requestQueue.getCount(); i++) {
- delete m_requestQueue[i];
- m_requestQueue.remove(i);
- }
- }
+
m_hRequestQueueThread = nullptr;
+ mir_cslock lock(m_requestQueueLock);
+ for (auto &it : m_requestQueue)
+ delete it;
+ m_requestQueue.destroy();
}
\ No newline at end of file diff --git a/protocols/VKontakte/src/vk_chats.cpp b/protocols/VKontakte/src/vk_chats.cpp index 4e82018e1a..55460df3d5 100644 --- a/protocols/VKontakte/src/vk_chats.cpp +++ b/protocols/VKontakte/src/vk_chats.cpp @@ -174,22 +174,22 @@ void CVkProto::OnReceiveChatInfo(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *pRe }
}
- for (int i = cc->m_users.getCount() - 1; i >= 0; i--) {
- CVkChatUser &cu = cc->m_users[i];
- if (!cu.m_bDel)
+ auto T = cc->m_users.rev_iter();
+ for (auto &cu : T) {
+ if (!cu->m_bDel)
continue;
wchar_t wszId[20];
- _itow(cu.m_uid, wszId, 10);
+ _itow(cu->m_uid, wszId, 10);
GCEVENT gce = { m_szModuleName, cc->m_wszId, GC_EVENT_PART };
gce.ptszUID = wszId;
gce.dwFlags = GCEF_NOTNOTIFY;
gce.time = time(nullptr);
- gce.ptszNick = mir_wstrdup(CMStringW(FORMAT, L"%s (https://vk.com/id%s)", cu.m_wszNick, wszId));
+ gce.ptszNick = mir_wstrdup(CMStringW(FORMAT, L"%s (https://vk.com/id%s)", cu->m_wszNick, wszId));
Chat_Event(&gce);
- cc->m_users.remove(i);
+ cc->m_users.remove(T.indexOf(&cu));
}
}
diff --git a/src/core/stdmsg/src/cmdlist.cpp b/src/core/stdmsg/src/cmdlist.cpp index 2b6c17fe5f..62f57de562 100644 --- a/src/core/stdmsg/src/cmdlist.cpp +++ b/src/core/stdmsg/src/cmdlist.cpp @@ -66,14 +66,12 @@ TMsgQueue* msgQueue_find(MCONTACT hContact, int id) mir_cslockfull lck(csMsgQueue);
for (auto &it : msgQueue) {
if ((it->hContact == hContact || it->hContact == hMeta) && it->id == id) {
- msgQueue.remove(it);
-
- if (!msgQueue.getCount() && timerId) {
+ if (msgQueue.getCount() == 1 && timerId) {
KillTimer(nullptr, timerId);
timerId = 0;
}
- return it;
+ return msgQueue.removeItem(&it);
}
}
return nullptr;
diff --git a/src/mir_app/src/extraicons.cpp b/src/mir_app/src/extraicons.cpp index 937b5e61a8..6428fc4b11 100644 --- a/src/mir_app/src/extraicons.cpp +++ b/src/mir_app/src/extraicons.cpp @@ -196,13 +196,12 @@ MIR_APP_DLL(void) KillModuleExtraIcons(int _hLang) {
LIST<ExtraIcon> arDeleted(1);
- for (int i = registeredExtraIcons.getCount() - 1; i >= 0; i--) {
- BaseExtraIcon *p = registeredExtraIcons[i];
- if (p->m_hLangpack == _hLang) {
- registeredExtraIcons.remove(i);
- arDeleted.insert(p);
+ auto T = registeredExtraIcons.rev_iter();
+ for (auto &it : T)
+ if (it->m_hLangpack == _hLang) {
+ arDeleted.insert(it);
+ registeredExtraIcons.remove(T.indexOf(&it));
}
- }
if (arDeleted.getCount() == 0)
return;
diff --git a/src/mir_app/src/hotkey_opts.cpp b/src/mir_app/src/hotkey_opts.cpp index 80d30e2531..5b3c7dc21c 100644 --- a/src/mir_app/src/hotkey_opts.cpp +++ b/src/mir_app/src/hotkey_opts.cpp @@ -758,8 +758,8 @@ static INT_PTR CALLBACK sttOptionsDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam, auto T = hotkeys.rev_iter(); for (auto &p : T) { if (p->OptNew && p->OptDeleted || p->rootHotkey && !p->OptHotkey || (lpnmhdr->code == PSN_APPLY) && p->OptDeleted || (lpnmhdr->code == PSN_RESET) && p->OptNew) { - hotkeys.remove(T.indexOf(&p)); FreeHotkey(p); + hotkeys.remove(T.indexOf(&p)); } } } diff --git a/src/mir_app/src/hotkeys.cpp b/src/mir_app/src/hotkeys.cpp index 4c3eabbcdf..e6f74830aa 100644 --- a/src/mir_app/src/hotkeys.cpp +++ b/src/mir_app/src/hotkeys.cpp @@ -223,8 +223,8 @@ MIR_APP_DLL(int) Hotkey_Unregister(const char *pszName) auto T = hotkeys.rev_iter();
for (auto &it : T)
if (it->UnregisterHotkey) {
- hotkeys.remove(T.indexOf(&it));
FreeHotkey(it);
+ hotkeys.remove(T.indexOf(&it));
}
return 0;
@@ -291,8 +291,8 @@ MIR_APP_DLL(void) KillModuleHotkeys(int _hLang) auto T = hotkeys.rev_iter();
for (auto &it : T)
if (it->hLangpack == _hLang) {
- hotkeys.remove(T.indexOf(&it));
FreeHotkey(it);
+ hotkeys.remove(T.indexOf(&it));
}
}
diff --git a/src/mir_app/src/icolib.cpp b/src/mir_app/src/icolib.cpp index 131df93618..b6c5405e81 100644 --- a/src/mir_app/src/icolib.cpp +++ b/src/mir_app/src/icolib.cpp @@ -601,8 +601,8 @@ MIR_APP_DLL(void) KillModuleIcons(int _hLang) auto T = iconList.rev_iter();
for (auto &it : T)
if (it->hLangpack == _hLang) {
- iconList.remove(T.indexOf(&it));
delete it;
+ iconList.remove(T.indexOf(&it));
}
}
@@ -810,11 +810,9 @@ void UnloadIcoLibModule(void) delete p;
iconSourceList.destroy();
- while (iconSourceFileList.getCount() > 0) {
- IconSourceFile *p = iconSourceFileList[0];
- iconSourceFileList.remove(0);
+ for (auto &p : iconSourceFileList)
mir_free(p);
- }
+ iconSourceFileList.destroy();
for (auto &p : sectionList)
delete p;
diff --git a/src/mir_app/src/meta_services.cpp b/src/mir_app/src/meta_services.cpp index f304f9452b..604b3064dc 100644 --- a/src/mir_app/src/meta_services.cpp +++ b/src/mir_app/src/meta_services.cpp @@ -557,7 +557,7 @@ static int Meta_MessageWindowEvent(WPARAM, LPARAM lParam) else if (mwed->uType == MSG_WINDOW_EVT_CLOSING)
for (auto &p : arMetaWindows)
if (p->m_hWnd == mwed->hwndWindow) {
- arMetaWindows.remove(p);
+ arMetaWindows.removeItem(&p);
break;
}
diff --git a/src/mir_app/src/newplugins.cpp b/src/mir_app/src/newplugins.cpp index b9ea1e7080..3dbd984dfa 100644 --- a/src/mir_app/src/newplugins.cpp +++ b/src/mir_app/src/newplugins.cpp @@ -728,7 +728,7 @@ void EnsureCheckerLoaded(bool bEnable) Plugin_Uninit(p);
else {
p->pclass |= PCLASS_LOADED;
- servicePlugins.remove(p);
+ servicePlugins.removeItem(&p);
}
}
}
diff --git a/src/mir_app/src/options.cpp b/src/mir_app/src/options.cpp index a9fe26c40a..ad7876ecca 100644 --- a/src/mir_app/src/options.cpp +++ b/src/mir_app/src/options.cpp @@ -1108,16 +1108,17 @@ public: void KillModule(int _hLang)
{
- for (int i = m_arOpd.getCount() - 1; i >= 0; i--) {
- OptionsPageData *opd = m_arOpd[i];
+ auto T = m_arOpd.rev_iter();
+ for (auto &opd : T) {
if (opd->hLangpack != _hLang)
continue;
- if (m_currentPage > i)
+ int idx = T.indexOf(&opd);
+ if (m_currentPage > idx)
m_currentPage--;
- m_arOpd.remove(i);
delete opd;
+ m_arOpd.remove(idx);
m_timerRebuild.Start(50);
}
}
diff --git a/src/mir_app/src/proto_accs.cpp b/src/mir_app/src/proto_accs.cpp index 187a4212b1..6132d25bcc 100644 --- a/src/mir_app/src/proto_accs.cpp +++ b/src/mir_app/src/proto_accs.cpp @@ -404,8 +404,8 @@ void UnloadAccountsModule() auto T = accounts.rev_iter();
for (auto &it : T) {
- accounts.remove(T.indexOf(&it));
UnloadAccount(it, false, false);
+ accounts.remove(T.indexOf(&it));
}
accounts.destroy();
diff --git a/src/mir_app/src/srmm_toolbar.cpp b/src/mir_app/src/srmm_toolbar.cpp index b0ba74df6d..a92343c2da 100644 --- a/src/mir_app/src/srmm_toolbar.cpp +++ b/src/mir_app/src/srmm_toolbar.cpp @@ -786,8 +786,8 @@ void KillModuleToolbarIcons(int _hLang) auto T = arButtonsList.rev_iter(); for (auto &cbd : T) if (cbd->m_hLangpack == _hLang) { - arButtonsList.remove(T.indexOf(&cbd)); delete cbd; + arButtonsList.remove(T.indexOf(&cbd)); } } diff --git a/src/mir_core/src/modules.cpp b/src/mir_core/src/modules.cpp index b78c204aff..a57f0d19ea 100644 --- a/src/mir_core/src/modules.cpp +++ b/src/mir_core/src/modules.cpp @@ -526,8 +526,8 @@ MIR_CORE_DLL(int) DestroyServiceFunction(HANDLE hService) { mir_cslock lck(csServices); - int idx; - if ((idx = services.getIndex((TService*)&hService)) != -1) { + int idx = services.getIndex((TService*)&hService); + if (idx != -1) { mir_free(services[idx]); services.remove(idx); } diff --git a/src/mir_core/src/threads.cpp b/src/mir_core/src/threads.cpp index 5be6150a91..a71d366585 100644 --- a/src/mir_core/src/threads.cpp +++ b/src/mir_core/src/threads.cpp @@ -236,8 +236,8 @@ MIR_CORE_DLL(void) KillObjectThreads(void* owner) Netlib_Logf(nullptr, "Killing object thread %s:%p", szModuleName, it->dwThreadId);
TerminateThread(it->hThread, 9999);
CloseHandle(it->hThread);
- threads.remove(T.indexOf(&it));
mir_free(it);
+ threads.remove(T.indexOf(&it));
}
}
}
diff --git a/src/mir_core/src/windowlist.cpp b/src/mir_core/src/windowlist.cpp index 9fe88f5c33..f997352fe9 100644 --- a/src/mir_core/src/windowlist.cpp +++ b/src/mir_core/src/windowlist.cpp @@ -68,7 +68,7 @@ MIR_CORE_DLL(int) WindowList_Remove(MWindowList hList, HWND hwnd) for (auto &it : *hList)
if (it->hWnd == hwnd) {
- hList->remove(it);
+ hList->removeItem(&it);
return 0;
}
|