From dad59528ccd770301b29c7db8148ff8ab8e89c92 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Wed, 14 Mar 2018 19:59:06 +0300 Subject: reverse iterators for LIST<> --- plugins/AVS/src/poll.cpp | 12 +++----- plugins/Clist_modern/src/modern_aniavatars.cpp | 7 ++--- plugins/FavContacts/src/contact_cache.cpp | 13 ++++---- .../src/historysweeperlight.cpp | 6 ++-- plugins/HistorySweeperLight/src/main.cpp | 2 +- plugins/Import/src/import.cpp | 8 ++--- plugins/NewXstatusNotify/src/main.cpp | 6 ++-- plugins/NewXstatusNotify/src/xstatus.cpp | 36 +++++++++------------- plugins/SmileyAdd/src/SmileyBase.cpp | 6 ++-- plugins/SmileyAdd/src/imagecache.cpp | 4 +-- plugins/SmileyAdd/src/richcall.cpp | 12 +++----- plugins/StartupSilence/src/main.cpp | 4 +-- plugins/TabSRMM/src/chat_main.cpp | 3 +- plugins/TabSRMM/src/eventpopups.cpp | 5 ++- plugins/TopToolBar/src/toolbar.cpp | 6 ++-- plugins/UserInfoEx/src/mir_contactqueue.cpp | 19 +++++------- 16 files changed, 66 insertions(+), 83 deletions(-) (limited to 'plugins') diff --git a/plugins/AVS/src/poll.cpp b/plugins/AVS/src/poll.cpp index 1c567c815b..3ba1bf90a0 100644 --- a/plugins/AVS/src/poll.cpp +++ b/plugins/AVS/src/poll.cpp @@ -104,11 +104,9 @@ static void QueueRemove(MCONTACT hContact) { mir_cslock lck(cs); - for (int i = queue.getCount() - 1; i >= 0; i--) { - QueueItem& item = queue[i]; - if (item.hContact == hContact) - queue.remove(i); - } + for (auto &it : queue.rev_iter()) + if (it->hContact == hContact) + queue.remove(it); } // Add an contact to a queue @@ -120,8 +118,8 @@ void QueueAdd(MCONTACT hContact, int waitTime) mir_cslock lck(cs); // Only add if not exists yet - for (int i = queue.getCount() - 1; i >= 0; i--) - if (queue[i].hContact == hContact) + for (auto &it : queue) + if (it->hContact == hContact) return; QueueItem *item = new QueueItem; diff --git a/plugins/Clist_modern/src/modern_aniavatars.cpp b/plugins/Clist_modern/src/modern_aniavatars.cpp index 2e3686782f..bc72629674 100644 --- a/plugins/Clist_modern/src/modern_aniavatars.cpp +++ b/plugins/Clist_modern/src/modern_aniavatars.cpp @@ -265,11 +265,10 @@ static void _AniAva_ResumePainting() static void _AniAva_ReduceAvatarImages(int startY, int dY, BOOL bDestroyWindow) { - for (int i = s_Objects.getCount() - 1; i >= 0; i--) { - ANIAVA_OBJECT &pai = s_Objects[i]; - int res = SendMessage(pai.hWindow, AAM_REMOVEAVATAR, (WPARAM)startY, (LPARAM)dY); + for (auto &it : s_Objects.rev_iter()) { + int res = SendMessage(it->hWindow, AAM_REMOVEAVATAR, (WPARAM)startY, (LPARAM)dY); if (res == 0xDEAD && bDestroyWindow) - s_Objects.remove(i); + s_Objects.remove(it); } } diff --git a/plugins/FavContacts/src/contact_cache.cpp b/plugins/FavContacts/src/contact_cache.cpp index d60cd00d84..5ebd3f1c71 100644 --- a/plugins/FavContacts/src/contact_cache.cpp +++ b/plugins/FavContacts/src/contact_cache.cpp @@ -38,13 +38,12 @@ int __cdecl CContactCache::OnDbEventAdded(WPARAM hContact, LPARAM hEvent) TContactInfo *pFound = nullptr; mir_cslock lck(m_cs); - for (int i = m_cache.getCount()-1; i >= 0; i--) { - TContactInfo *p = m_cache[i]; - p->rate *= q; - if (p->hContact == hContact) { - p->rate += weight; - pFound = p; - m_cache.remove(i); // reinsert to maintain the sort order + for (auto &it : m_cache.rev_iter()) { + it->rate *= q; + if (it->hContact == hContact) { + it->rate += weight; + pFound = it; + m_cache.remove(it); // reinsert to maintain the sort order } } diff --git a/plugins/HistorySweeperLight/src/historysweeperlight.cpp b/plugins/HistorySweeperLight/src/historysweeperlight.cpp index ad73c5d46c..65c37b0196 100644 --- a/plugins/HistorySweeperLight/src/historysweeperlight.cpp +++ b/plugins/HistorySweeperLight/src/historysweeperlight.cpp @@ -224,9 +224,9 @@ int OnWindowEvent(WPARAM, LPARAM lParam) SweepHistoryFromContact(msgEvData->hContact, Criteria, TRUE); } - for (int i = g_hWindows.getCount() - 1; i >= 0; i--) - if (g_hWindows[i] == PVOID(msgEvData->hContact)) - g_hWindows.remove(i); + for (auto &it : g_hWindows.rev_iter()) + if (it == PVOID(msgEvData->hContact)) + g_hWindows.remove(it); break; } diff --git a/plugins/HistorySweeperLight/src/main.cpp b/plugins/HistorySweeperLight/src/main.cpp index 0c1fdc4aac..e0fee84c71 100644 --- a/plugins/HistorySweeperLight/src/main.cpp +++ b/plugins/HistorySweeperLight/src/main.cpp @@ -25,7 +25,7 @@ HINSTANCE hInst; int hLangpack; -LIST g_hWindows(5); +LIST g_hWindows(5, PtrKeySortT); static PLUGININFOEX pluginInfoEx = { diff --git a/plugins/Import/src/import.cpp b/plugins/Import/src/import.cpp index 590bce6a5a..7a133ae62b 100644 --- a/plugins/Import/src/import.cpp +++ b/plugins/Import/src/import.cpp @@ -165,11 +165,11 @@ void CopySettings(MCONTACT srcID, const char *szSrcModule, MCONTACT dstID, const LIST arSettings(50); srcDb->EnumContactSettings(srcID, CopySettingsEnum, szSrcModule, &arSettings); - for (int i = arSettings.getCount() - 1; i >= 0; i--) { + for (auto &it : arSettings.rev_iter()) { DBVARIANT dbv = { 0 }; - if (!srcDb->GetContactSetting(srcID, szSrcModule, arSettings[i], &dbv)) - db_set(dstID, szDstModule, arSettings[i], &dbv); - mir_free(arSettings[i]); + if (!srcDb->GetContactSetting(srcID, szSrcModule, it, &dbv)) + db_set(dstID, szDstModule, it, &dbv); + mir_free(it); } } diff --git a/plugins/NewXstatusNotify/src/main.cpp b/plugins/NewXstatusNotify/src/main.cpp index 70a7303963..7345ebb3e0 100644 --- a/plugins/NewXstatusNotify/src/main.cpp +++ b/plugins/NewXstatusNotify/src/main.cpp @@ -25,9 +25,9 @@ CLIST_INTERFACE *pcli; HINSTANCE hInst; -LIST eventListXStatus(10); -LIST eventListStatus(10); -LIST eventListSMsg(10); +LIST eventListXStatus(10, PtrKeySortT); +LIST eventListStatus(10, PtrKeySortT); +LIST eventListSMsg(10, PtrKeySortT); HANDLE hStatusModeChange, hHookContactStatusChanged, hToolbarButton; HGENMENU hEnableDisableMenu; diff --git a/plugins/NewXstatusNotify/src/xstatus.cpp b/plugins/NewXstatusNotify/src/xstatus.cpp index a3cacaecb0..a582c8e5c7 100644 --- a/plugins/NewXstatusNotify/src/xstatus.cpp +++ b/plugins/NewXstatusNotify/src/xstatus.cpp @@ -42,38 +42,32 @@ void FreeXSC(XSTATUSCHANGE *xsc) void RemoveLoggedEventsXStatus(MCONTACT hContact) { - for (int i = eventListXStatus.getCount() - 1; i >= 0; i--) { - DBEVENT *dbevent = eventListXStatus[i]; - if (dbevent->hContact == hContact) { - db_event_delete(dbevent->hContact, dbevent->hDBEvent); - eventListXStatus.remove(i); - mir_free(dbevent); + for (auto &it : eventListXStatus.rev_iter()) + if (it->hContact == hContact) { + db_event_delete(it->hContact, it->hDBEvent); + eventListXStatus.remove(it); + mir_free(it); } - } } void RemoveLoggedEventsStatus(MCONTACT hContact) { - for (int i = eventListStatus.getCount() - 1; i >= 0; i--) { - DBEVENT *dbevent = eventListStatus[i]; - if (dbevent->hContact == hContact) { - db_event_delete(dbevent->hContact, dbevent->hDBEvent); - eventListStatus.remove(i); - mir_free(dbevent); + for (auto &it : eventListStatus.rev_iter()) + if (it->hContact == hContact) { + db_event_delete(it->hContact, it->hDBEvent); + eventListStatus.remove(it); + mir_free(it); } - } } void RemoveLoggedEventsSMsg(MCONTACT hContact) { - for (int i = eventListSMsg.getCount() - 1; i >= 0; i--) { - DBEVENT *dbevent = eventListSMsg[i]; - if (dbevent->hContact == hContact) { - db_event_delete(dbevent->hContact, dbevent->hDBEvent); - eventListSMsg.remove(i); - mir_free(dbevent); + for (auto &it : eventListSMsg.rev_iter()) + if (it->hContact == hContact) { + db_event_delete(it->hContact, it->hDBEvent); + eventListSMsg.remove(it); + mir_free(it); } - } } wchar_t* GetStatusTypeAsString(int type, wchar_t *buff) diff --git a/plugins/SmileyAdd/src/SmileyBase.cpp b/plugins/SmileyAdd/src/SmileyBase.cpp index 3ecc9e7a10..e9ef6722d8 100644 --- a/plugins/SmileyAdd/src/SmileyBase.cpp +++ b/plugins/SmileyAdd/src/SmileyBase.cpp @@ -368,9 +368,9 @@ HRESULT ISmileyBase::GetTooltip(BSTR *bstrHint) void CloseSmileys(void) { - for (int i = regSmileys.getCount() - 1; i >= 0; i--) { - regSmileys[i]->OnClose(); - regSmileys[i]->Close(OLECLOSE_NOSAVE); + for (auto &it : regSmileys.rev_iter()) { + it->OnClose(); + it->Close(OLECLOSE_NOSAVE); } } diff --git a/plugins/SmileyAdd/src/imagecache.cpp b/plugins/SmileyAdd/src/imagecache.cpp index 87043a9e26..cbf5c69a39 100644 --- a/plugins/SmileyAdd/src/imagecache.cpp +++ b/plugins/SmileyAdd/src/imagecache.cpp @@ -36,8 +36,8 @@ static void CALLBACK timerProc(HWND, UINT, UINT_PTR, DWORD) lastdllname.Empty(); } - for (int i = g_imagecache.getCount() - 1; i >= 0; i--) - g_imagecache[i].ProcessTimerTick(ts); + for (auto &it : g_imagecache.rev_iter()) + it->ProcessTimerTick(ts); if (g_imagecache.getCount() == 0) { g_imagecache.destroy(); diff --git a/plugins/SmileyAdd/src/richcall.cpp b/plugins/SmileyAdd/src/richcall.cpp index 67ab0a5c98..a5a81e12cb 100644 --- a/plugins/SmileyAdd/src/richcall.cpp +++ b/plugins/SmileyAdd/src/richcall.cpp @@ -421,8 +421,7 @@ void CloseRichOwnerCallback(HWND hwnd) void ProcessAllInputAreas(bool restoreText) { - for (int i = g_RichEditList.getCount() - 1; i >= 0; i--) { - RichEditData *rdt = g_RichEditList[i]; + for (auto &rdt : g_RichEditList.rev_iter()) if (rdt->inputarea) { if (restoreText) { CHARRANGE sel = allsel; @@ -430,16 +429,15 @@ void ProcessAllInputAreas(bool restoreText) } else ReplaceContactSmileys(rdt, allsel, false, false); } - } } void RichEditData_Destroy(void) { - for (int i = g_RichEditList.getCount() - 1; i >= 0; i--) - CloseRichCallback(g_RichEditList[i]->hwnd); + for (auto &it : g_RichEditList.rev_iter()) + CloseRichCallback(it->hwnd); g_RichEditList.destroy(); - for (int i = g_RichEditOwnerList.getCount() - 1; i >= 0; i--) - CloseRichOwnerCallback(g_RichEditOwnerList[i]->hwnd); + for (auto &it : g_RichEditOwnerList.rev_iter()) + CloseRichOwnerCallback(it->hwnd); g_RichEditOwnerList.destroy(); } diff --git a/plugins/StartupSilence/src/main.cpp b/plugins/StartupSilence/src/main.cpp index af56a5e6c9..4c525f867d 100644 --- a/plugins/StartupSilence/src/main.cpp +++ b/plugins/StartupSilence/src/main.cpp @@ -332,8 +332,8 @@ static int CreateTTButtons(WPARAM, LPARAM) void RemoveTTButtons() { - for (int i=ttbButtons.getCount()-1; i >= 0; i--) - CallService(MS_TTB_REMOVEBUTTON, (WPARAM)ttbButtons[i], 0); + for (auto &it : ttbButtons.rev_iter()) + CallService(MS_TTB_REMOVEBUTTON, (WPARAM)it, 0); ttbButtons.destroy(); } diff --git a/plugins/TabSRMM/src/chat_main.cpp b/plugins/TabSRMM/src/chat_main.cpp index c3fe689df4..0f03ecf541 100644 --- a/plugins/TabSRMM/src/chat_main.cpp +++ b/plugins/TabSRMM/src/chat_main.cpp @@ -174,8 +174,7 @@ static void CheckUpdate() db_enum_settings(0, CopyChatSetting, CHAT_OLDFONTMODULE, &szSettings); DBVARIANT dbv; - for (int i = szSettings.getCount() - 1; i >= 0; i--) { - char *p = szSettings[i]; + for (auto &p : szSettings.rev_iter()) { db_get(0, CHAT_OLDFONTMODULE, p, &dbv); db_set(0, CHATFONT_MODULE, p, &dbv); db_free(&dbv); diff --git a/plugins/TabSRMM/src/eventpopups.cpp b/plugins/TabSRMM/src/eventpopups.cpp index 3f642787b9..4b022070db 100644 --- a/plugins/TabSRMM/src/eventpopups.cpp +++ b/plugins/TabSRMM/src/eventpopups.cpp @@ -54,14 +54,13 @@ static PLUGIN_DATAT* PU_GetByContact(const MCONTACT hContact) */ static void PU_CleanUp() { - for (int i = arPopupList.getCount() - 1; i >= 0; i--) { - PLUGIN_DATAT *p = arPopupList[i]; + for (auto &p : arPopupList.rev_iter()) { if (p->hContact != 0) continue; mir_free(p->eventData); mir_free(p); - arPopupList.remove(i); + arPopupList.remove(p); } } diff --git a/plugins/TopToolBar/src/toolbar.cpp b/plugins/TopToolBar/src/toolbar.cpp index de6755c5d8..380daf02dd 100644 --- a/plugins/TopToolBar/src/toolbar.cpp +++ b/plugins/TopToolBar/src/toolbar.cpp @@ -550,9 +550,9 @@ int OnPluginUnload(WPARAM, LPARAM lParam) bool bNeedUpdate = false; mir_cslock lck(csButtonsHook); - for (int i = Buttons.getCount() - 1; i >= 0; i--) - if (Buttons[i]->hLangpack == lang) { - TTBRemoveButton(Buttons[i]->id, 0); + for (auto &it : Buttons.rev_iter()) + if (it->hLangpack == lang) { + TTBRemoveButton(it->id, 0); bNeedUpdate = true; } diff --git a/plugins/UserInfoEx/src/mir_contactqueue.cpp b/plugins/UserInfoEx/src/mir_contactqueue.cpp index 9a734ba968..752a9fbbc5 100644 --- a/plugins/UserInfoEx/src/mir_contactqueue.cpp +++ b/plugins/UserInfoEx/src/mir_contactqueue.cpp @@ -71,8 +71,8 @@ void CContactQueue::RemoveAll() { mir_cslock lck(_cs); - for (int i = _queue.getCount() - 1; i >= 0; --i) - mir_free(_queue[i]); + for (auto &it : _queue) + mir_free(it); _queue.destroy(); } @@ -83,10 +83,9 @@ void CContactQueue::RemoveAll(MCONTACT hContact) { mir_cslock lck(_cs); - for (int i = _queue.getCount() - 1; i >= 0; --i) { - CQueueItem *qi = _queue[i]; + for (auto &qi : _queue.rev_iter()) { if (qi->hContact == hContact) { - _queue.remove(i); + _queue.remove(qi); mir_free(qi); } } @@ -99,13 +98,11 @@ void CContactQueue::RemoveAllConsiderParam(MCONTACT hContact, PVOID param) { mir_cslock lck(_cs); - for (int i = _queue.getCount() - 1; i >= 0; --i) { - CQueueItem *qi = _queue[i]; + for (auto &qi : _queue.rev_iter()) if (qi->hContact == hContact && qi->param == param) { - _queue.remove(i); + _queue.remove(qi); mir_free(qi); } - } } ///////////////////////////////////////////////////////////////////////////////////////// @@ -125,8 +122,8 @@ BOOL CContactQueue::AddIfDontHave(int waitTime, MCONTACT hContact, PVOID param) { mir_cslock lck(_cs); - for (int i = _queue.getCount() - 1; i >= 0; --i) - if (_queue[i]->hContact == hContact) + for (auto &qi : _queue.rev_iter()) + if (qi->hContact == hContact) return FALSE; return InternalAdd(waitTime, hContact, param); -- cgit v1.2.3