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<> --- src/core/stdmsg/src/cmdlist.cpp | 10 +++----- src/mir_app/src/FontService.cpp | 18 ++++++------- src/mir_app/src/MDatabaseCommon.cpp | 6 ++--- src/mir_app/src/chat_manager.cpp | 5 ++-- src/mir_app/src/clistsettings.cpp | 9 +++---- src/mir_app/src/hotkey_opts.cpp | 6 ++--- src/mir_app/src/hotkeys.cpp | 18 ++++++------- src/mir_app/src/icolib.cpp | 34 ++++++++++++------------- src/mir_app/src/newplugins.cpp | 31 +++++++++-------------- src/mir_app/src/proto_accs.cpp | 7 +++--- src/mir_app/src/sounds.cpp | 34 ++++++++----------------- src/mir_app/src/srmm_statusicon.cpp | 21 +++++++--------- src/mir_app/src/srmm_toolbar.cpp | 30 +++++++--------------- src/mir_app/src/usedIcons.cpp | 9 +++---- src/mir_core/src/modules.cpp | 50 ++++++++++++++++++------------------- src/mir_core/src/subclass.cpp | 13 +++++----- src/mir_core/src/threads.cpp | 17 ++++++------- src/mir_core/src/windowlist.cpp | 8 +++--- 18 files changed, 138 insertions(+), 188 deletions(-) (limited to 'src') diff --git a/src/core/stdmsg/src/cmdlist.cpp b/src/core/stdmsg/src/cmdlist.cpp index 3b44e921c9..23c6fbe20b 100644 --- a/src/core/stdmsg/src/cmdlist.cpp +++ b/src/core/stdmsg/src/cmdlist.cpp @@ -32,13 +32,11 @@ static VOID CALLBACK MsgTimer(HWND, UINT, UINT_PTR, DWORD dwTime) LIST arTimedOut(1); { mir_cslock lck(csMsgQueue); - for (int i = msgQueue.getCount() - 1; i >= 0; i--) { - TMsgQueue *item = msgQueue[i]; - if (dwTime - item->ts > g_dat.msgTimeout) { - arTimedOut.insert(item); - msgQueue.remove(i); + for (auto &it : msgQueue.rev_iter()) + if (dwTime - it->ts > g_dat.msgTimeout) { + arTimedOut.insert(it); + msgQueue.remove(it); } - } } for (auto &it : arTimedOut) diff --git a/src/mir_app/src/FontService.cpp b/src/mir_app/src/FontService.cpp index b30cfa7344..58e3caede1 100644 --- a/src/mir_app/src/FontService.cpp +++ b/src/mir_app/src/FontService.cpp @@ -326,9 +326,9 @@ static INT_PTR ReloadFonts(WPARAM, LPARAM) MIR_APP_DLL(void) KillModuleFonts(int _hLang) { - for (int i = font_id_list.getCount() - 1; i >= 0; i--) - if (font_id_list[i].hLangpack == _hLang) - font_id_list.remove(i); + for (auto &it : font_id_list.rev_iter()) + if (it->hLangpack == _hLang) + font_id_list.remove(it); } ///////////////////////////////////////////////////////////////////////////////////////// @@ -401,9 +401,9 @@ static INT_PTR ReloadColours(WPARAM, LPARAM) MIR_APP_DLL(void) KillModuleColours(int _hLang) { - for (int i = colour_id_list.getCount() - 1; i >= 0; i--) - if (colour_id_list[i].hLangpack == _hLang) - colour_id_list.remove(i); + for (auto &it : colour_id_list.rev_iter()) + if (it->hLangpack == _hLang) + colour_id_list.remove(it); } ////////////////////////////////////////////////////////////////////////// @@ -484,9 +484,9 @@ MIR_APP_DLL(int) Effect_Get(const char *szGroup, const char *szName, FONTEFFECT MIR_APP_DLL(void) KillModuleEffects(int _hLang) { - for (int i = effect_id_list.getCount() - 1; i >= 0; i--) - if (effect_id_list[i].hLangpack == _hLang) - effect_id_list.remove(i); + for (auto &it : effect_id_list.rev_iter()) + if (it->hLangpack == _hLang) + effect_id_list.remove(it); } ///////////////////////////////////////////////////////////////////////////////////////// diff --git a/src/mir_app/src/MDatabaseCommon.cpp b/src/mir_app/src/MDatabaseCommon.cpp index c909a57e77..dd3034a00e 100644 --- a/src/mir_app/src/MDatabaseCommon.cpp +++ b/src/mir_app/src/MDatabaseCommon.cpp @@ -75,9 +75,9 @@ BOOL MDatabaseCommon::DeleteModule(MCONTACT hContact, LPCSTR szModule) LIST vars(20); EnumContactSettings(hContact, sttEnumVars, szModule, &vars); - for (int i = vars.getCount() - 1; i >= 0; i--) { - DeleteContactSetting(hContact, szModule, vars[i]); - mir_free(vars[i]); + for (auto &it : vars.rev_iter()) { + DeleteContactSetting(hContact, szModule, it); + mir_free(it); } return 0; } diff --git a/src/mir_app/src/chat_manager.cpp b/src/mir_app/src/chat_manager.cpp index 17a34ec221..bf97ad42b1 100644 --- a/src/mir_app/src/chat_manager.cpp +++ b/src/mir_app/src/chat_manager.cpp @@ -136,11 +136,10 @@ int SM_RemoveSession(const wchar_t *pszID, const char *pszModule, bool removeCon return TRUE; } - for (int i = g_arSessions.getCount() - 1; i >= 0; i--) { - SESSION_INFO *si = g_arSessions[i]; + for (auto &si : g_arSessions.rev_iter()) { if (si->iType != GCW_SERVER && !mir_strcmpi(si->pszModule, pszModule)) { SM_FreeSession(si, removeContact); - g_arSessions.remove(i); + g_arSessions.remove(si); } } return TRUE; diff --git a/src/mir_app/src/clistsettings.cpp b/src/mir_app/src/clistsettings.cpp index 975321c410..c2272920f8 100644 --- a/src/mir_app/src/clistsettings.cpp +++ b/src/mir_app/src/clistsettings.cpp @@ -147,11 +147,10 @@ int ContactDeleted(WPARAM hContact, LPARAM) } // remove events for a contact - for (int i = g_cliEvents.getCount() - 1; i >= 0; i--) { - CListEvent &e = g_cliEvents[i]; - if (e.hContact == hContact) - cli.pfnRemoveEvent(hContact, e.hDbEvent); - } + for (auto &it : g_cliEvents.rev_iter()) + if (it->hContact == hContact) + cli.pfnRemoveEvent(hContact, it->hDbEvent); + return 0; } diff --git a/src/mir_app/src/hotkey_opts.cpp b/src/mir_app/src/hotkey_opts.cpp index 28b852993d..b09a7e0944 100644 --- a/src/mir_app/src/hotkey_opts.cpp +++ b/src/mir_app/src/hotkey_opts.cpp @@ -755,13 +755,11 @@ static INT_PTR CALLBACK sttOptionsDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam, UnregisterHotkeys(); - for (int i = hotkeys.getCount()-1; i--;) { - THotkeyItem *p = hotkeys[i]; + for (auto &p : hotkeys.rev_iter()) if (p->OptNew && p->OptDeleted || p->rootHotkey && !p->OptHotkey || (lpnmhdr->code == PSN_APPLY) && p->OptDeleted || (lpnmhdr->code == PSN_RESET) && p->OptNew) { + hotkeys.remove(p); FreeHotkey(p); - hotkeys.remove(i); } - } if (lpnmhdr->code == PSN_APPLY) { LVITEM lvi = { 0 }; diff --git a/src/mir_app/src/hotkeys.cpp b/src/mir_app/src/hotkeys.cpp index 6443955168..36016bdd59 100644 --- a/src/mir_app/src/hotkeys.cpp +++ b/src/mir_app/src/hotkeys.cpp @@ -220,10 +220,10 @@ MIR_APP_DLL(int) Hotkey_Unregister(const char *pszName) if (g_hwndHkOptions) SendMessage(g_hwndHkOptions, WM_HOTKEYUNREGISTERED, 0, 0); - for (int i = hotkeys.getCount()-1; i >= 0; i--) - if (hotkeys[i]->UnregisterHotkey) { - FreeHotkey(hotkeys[i]); - hotkeys.remove(i); + for (auto &it : hotkeys.rev_iter()) + if (it->UnregisterHotkey) { + hotkeys.remove(it); + FreeHotkey(it); } return 0; @@ -287,13 +287,11 @@ void RegisterHotkeys() MIR_APP_DLL(void) KillModuleHotkeys(int _hLang) { - for (int i = hotkeys.getCount()-1; i >= 0; i--) { - THotkeyItem *p = hotkeys[i]; - if (p->hLangpack == _hLang) { - FreeHotkey(p); - hotkeys.remove(i); + for (auto &it : hotkeys.rev_iter()) + if (it->hLangpack == _hLang) { + hotkeys.remove(it); + FreeHotkey(it); } - } } void UnregisterHotkeys() diff --git a/src/mir_app/src/icolib.cpp b/src/mir_app/src/icolib.cpp index b3e212f3f3..27d49a1dc6 100644 --- a/src/mir_app/src/icolib.cpp +++ b/src/mir_app/src/icolib.cpp @@ -570,20 +570,15 @@ MIR_APP_DLL(int) IcoLib_Release(const char *szIconName, bool big) ///////////////////////////////////////////////////////////////////////////////////////// // IcoLib_RemoveIcon -__inline void IcoLib_RemoveIcon_Internal(int i) -{ - IcolibItem *item = iconList[i]; - iconList.remove(i); - delete item; -} - MIR_APP_DLL(void) IcoLib_RemoveIcon(const char *pszIconName) { mir_cslock lck(csIconList); int i = iconList.indexOf((IcolibItem*)&pszIconName); - if (i != -1) - IcoLib_RemoveIcon_Internal(i); + if (i != -1) { + iconList.remove(i); + delete iconList[i]; + } } MIR_APP_DLL(void) IcoLib_RemoveIconByHandle(HANDLE hIcoLib) @@ -591,8 +586,10 @@ MIR_APP_DLL(void) IcoLib_RemoveIconByHandle(HANDLE hIcoLib) mir_cslock lck(csIconList); int i = iconList.getIndex((IcolibItem*)hIcoLib); - if (i != -1) - IcoLib_RemoveIcon_Internal(i); + if (i != -1) { + iconList.remove(i); + delete iconList[i]; + } } MIR_APP_DLL(void) KillModuleIcons(int _hLang) @@ -601,11 +598,11 @@ MIR_APP_DLL(void) KillModuleIcons(int _hLang) return; mir_cslock lck(csIconList); - for (int i = iconList.getCount() - 1; i >= 0; i--) { - IcolibItem *item = iconList[i]; - if (item->hLangpack == _hLang) - IcoLib_RemoveIcon_Internal(i); - } + for (auto &it : iconList.rev_iter()) + if (it->hLangpack == _hLang) { + iconList.remove(it); + delete it; + } } ///////////////////////////////////////////////////////////////////////////////////////// @@ -804,8 +801,9 @@ void UnloadIcoLibModule(void) DestroyHookableEvent(hIconsChangedEvent); DestroyHookableEvent(hIcons2ChangedEvent); - while (iconList.getCount() > 0) - IcoLib_RemoveIcon_Internal(0); + for (auto &p : iconList) + delete p; + iconList.destroy(); for (auto &p : iconSourceList) delete p; diff --git a/src/mir_app/src/newplugins.cpp b/src/mir_app/src/newplugins.cpp index b8a3d4bba2..b9ea1e7080 100644 --- a/src/mir_app/src/newplugins.cpp +++ b/src/mir_app/src/newplugins.cpp @@ -653,11 +653,10 @@ static pluginEntry* getCListModule(wchar_t *exe) int UnloadPlugin(wchar_t* buf, int bufLen) { - for (int i = pluginList.getCount() - 1; i >= 0; i--) { - pluginEntry *p = pluginList[i]; - if (!mir_wstrcmpi(p->pluginname, buf)) { - GetModuleFileName(p->bpi.hInst, buf, bufLen); - Plugin_Uninit(p); + for (auto &it : pluginList.rev_iter()) { + if (!mir_wstrcmpi(it->pluginname, buf)) { + GetModuleFileName(it->bpi.hInst, buf, bufLen); + Plugin_Uninit(it); return TRUE; } } @@ -767,11 +766,9 @@ int LoadSslModule(void) void UnloadNewPlugins(void) { // unload everything but the special db/clist plugins - for (int i = pluginList.getCount() - 1; i >= 0; i--) { - pluginEntry *p = pluginList[i]; - if (!(p->pclass & PCLASS_LAST) && (p->pclass & PCLASS_OK)) - Plugin_Uninit(p); - } + for (auto &it : pluginList.rev_iter()) + if (!(it->pclass & PCLASS_LAST) && (it->pclass & PCLASS_OK)) + Plugin_Uninit(it); } ///////////////////////////////////////////////////////////////////////////////////////// @@ -885,21 +882,17 @@ void UnloadNewPluginsModule(void) UnloadPluginOptions(); // unload everything but the DB - for (int i = pluginList.getCount() - 1; i >= 0; i--) { - pluginEntry *p = pluginList[i]; - if (!(p->pclass & (PCLASS_DB | PCLASS_CRYPT)) && p != plugin_crshdmp) - Plugin_Uninit(p); - } + for (auto &it : pluginList.rev_iter()) + if (!(it->pclass & (PCLASS_DB | PCLASS_CRYPT)) && it != plugin_crshdmp) + Plugin_Uninit(it); if (plugin_crshdmp) Plugin_Uninit(plugin_crshdmp); UnloadDatabase(); - for (int k = pluginList.getCount() - 1; k >= 0; k--) { - pluginEntry *p = pluginList[k]; - Plugin_Uninit(p); - } + for (auto &it : pluginList.rev_iter()) + Plugin_Uninit(it); if (hPluginListHeap) HeapDestroy(hPluginListHeap); diff --git a/src/mir_app/src/proto_accs.cpp b/src/mir_app/src/proto_accs.cpp index 3a701e1188..ad1896e29d 100644 --- a/src/mir_app/src/proto_accs.cpp +++ b/src/mir_app/src/proto_accs.cpp @@ -402,10 +402,9 @@ void UnloadAccountsModule() { if (!bModuleInitialized) return; - for (int i = accounts.getCount() - 1; i >= 0; i--) { - PROTOACCOUNT *pa = accounts[i]; - UnloadAccount(pa, false, false); - accounts.remove(i); + for (auto &it : accounts.rev_iter()) { + accounts.remove(it); + UnloadAccount(it, false, false); } accounts.destroy(); diff --git a/src/mir_app/src/sounds.cpp b/src/mir_app/src/sounds.cpp index 11d66ef688..27128138cf 100644 --- a/src/mir_app/src/sounds.cpp +++ b/src/mir_app/src/sounds.cpp @@ -28,22 +28,14 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. struct SoundItem { - char* name; - wchar_t* pwszSection; - wchar_t* pwszDescription; - wchar_t* ptszTempFile; - int hLangpack; + ptrA name; + ptrW pwszSection; + ptrW pwszDescription; + ptrW ptszTempFile; + int hLangpack; __inline wchar_t* getSection() const { return TranslateW_LP(pwszSection, hLangpack); } __inline wchar_t* getDescr() const { return TranslateW_LP(pwszDescription, hLangpack); } - - __inline void clear(void) - { - mir_free(name); - mir_free(pwszSection); - mir_free(pwszDescription); - mir_free(ptszTempFile); - } }; static int CompareSounds(const SoundItem* p1, const SoundItem* p2) @@ -57,13 +49,9 @@ static OBJLIST arSounds(10, CompareSounds); MIR_APP_DLL(void) KillModuleSounds(int _hLang) { - for (int i = arSounds.getCount() - 1; i >= 0; i--) { - SoundItem &p = arSounds[i]; - if (p.hLangpack == _hLang) { - p.clear(); - arSounds.remove(i); - } - } + for (auto &it : arSounds.rev_iter()) + if (it->hLangpack == _hLang) + arSounds.remove(it); } ///////////////////////////////////////////////////////////////////////////////////////// @@ -118,8 +106,7 @@ MIR_APP_DLL(int) Skin_PlaySound(const char *pszSoundName) if (pszSoundName == nullptr) return 1; - SoundItem tmp = { (char*)pszSoundName }; - int idx = arSounds.getIndex(&tmp); + int idx = arSounds.getIndex((SoundItem*)&pszSoundName); if (idx == -1) return 1; @@ -472,6 +459,5 @@ int LoadSkinSounds(void) void UnloadSkinSounds(void) { - for (auto &p : arSounds) - p->clear(); + arSounds.destroy(); } diff --git a/src/mir_app/src/srmm_statusicon.cpp b/src/mir_app/src/srmm_statusicon.cpp index 97637bd3ef..c30d3d3ec0 100644 --- a/src/mir_app/src/srmm_statusicon.cpp +++ b/src/mir_app/src/srmm_statusicon.cpp @@ -163,19 +163,18 @@ MIR_APP_DLL(StatusIconData*) Srmm_GetNthIcon(MCONTACT hContact, int index) { static StatusIconData res; - for (int i=arIcons.getCount()-1, nVis = 0; i >= 0; i--) { - StatusIconMain &p = arIcons[i]; - - StatusIconChild *pc = p.arChildren.find((StatusIconChild*)&hContact); + int nVis = 0; + for (auto &it : arIcons.rev_iter()) { + StatusIconChild *pc = it->arChildren.find((StatusIconChild*)&hContact); if (pc) { if (pc->flags & MBF_HIDDEN) continue; } - else if (p.sid.flags & MBF_HIDDEN) + else if (it->sid.flags & MBF_HIDDEN) continue; if (nVis == index) { - memcpy(&res, &p, sizeof(res)); + memcpy(&res, it, sizeof(res)); if (pc) { if (pc->hIcon) res.hIcon = pc->hIcon; if (pc->hIconDisabled) @@ -185,7 +184,7 @@ MIR_APP_DLL(StatusIconData*) Srmm_GetNthIcon(MCONTACT hContact, int index) if (pc->tszTooltip) res.tszTooltip = pc->tszTooltip; res.flags = pc->flags; } - res.tszTooltip = TranslateW_LP(res.tszTooltip, p.hLangpack); + res.tszTooltip = TranslateW_LP(res.tszTooltip, it->hLangpack); return &res; } nVis++; @@ -198,11 +197,9 @@ MIR_APP_DLL(StatusIconData*) Srmm_GetNthIcon(MCONTACT hContact, int index) void KillModuleSrmmIcons(int _hLang) { - for (int i = arIcons.getCount()-1; i >= 0; i--) { - StatusIconMain &p = arIcons[i]; - if (p.hLangpack == _hLang) - arIcons.remove(i); - } + for (auto &it : arIcons.rev_iter()) + if (it->hLangpack == _hLang) + arIcons.remove(it); } int LoadSrmmModule() diff --git a/src/mir_app/src/srmm_toolbar.cpp b/src/mir_app/src/srmm_toolbar.cpp index 8069a1c42c..d3b0d7c278 100644 --- a/src/mir_app/src/srmm_toolbar.cpp +++ b/src/mir_app/src/srmm_toolbar.cpp @@ -52,14 +52,6 @@ int dwSepCount = 0; static mir_cs csToolBar; static HANDLE hHookToolBarLoadedEvt, hHookButtonPressedEvt; -static void wipeList(LIST &list) -{ - for (int i = list.getCount() - 1; i >= 0; i--) { - delete list[i]; - list.remove(i); - } -} - static int sstSortButtons(const void *p1, const void *p2) { return SortButtons(*(CustomButtonData**)p1, *(CustomButtonData**)p2); @@ -228,13 +220,11 @@ MIR_APP_DLL(int) Srmm_RemoveButton(BBButton *bbdi) { mir_cslock lck(csToolBar); - for (int i = arButtonsList.getCount() - 1; i >= 0; i--) { - CustomButtonData *cbd = arButtonsList[i]; + for (auto &cbd : arButtonsList.rev_iter()) if (!mir_strcmp(cbd->m_pszModuleName, bbdi->pszModuleName) && cbd->m_dwButtonID == bbdi->dwButtonID) { pFound = cbd; - arButtonsList.remove(i); + arButtonsList.remove(cbd); } - } } if (pFound) { @@ -432,14 +422,12 @@ MIR_APP_DLL(void) Srmm_RedrawToolbarIcons(HWND hwndDlg) static void CB_ReInitCustomButtons() { - for (int i = arButtonsList.getCount() - 1; i >= 0; i--) { - CustomButtonData *cbd = arButtonsList[i]; - + for (auto &cbd : arButtonsList.rev_iter()) { if (cbd->m_opFlags & (BBSF_NTBSWAPED | BBSF_NTBDESTRUCT)) { cbd->m_opFlags ^= BBSF_NTBSWAPED; if (cbd->m_opFlags & BBSF_NTBDESTRUCT) - arButtonsList.remove(i); + arButtonsList.remove(cbd); } } qsort(arButtonsList.getArray(), arButtonsList.getCount(), sizeof(void*), sstSortButtons); @@ -793,13 +781,11 @@ static int SrmmOptionsInit(WPARAM wParam, LPARAM) void KillModuleToolbarIcons(int _hLang) { - for (int i = arButtonsList.getCount() - 1; i >= 0; i--) { - CustomButtonData *cbd = arButtonsList[i]; + for (auto &cbd : arButtonsList.rev_iter()) if (cbd->m_hLangpack == _hLang) { - arButtonsList.remove(i); + arButtonsList.remove(cbd); delete cbd; } - } } static INT_PTR BroadcastMessage(WPARAM, LPARAM lParam) @@ -860,5 +846,7 @@ void UnloadSrmmToolbarModule() { DestroyHookableEvent(hHookButtonPressedEvt); - wipeList(arButtonsList); + for (auto &it : arButtonsList) + delete it; + arButtonsList.destroy(); } diff --git a/src/mir_app/src/usedIcons.cpp b/src/mir_app/src/usedIcons.cpp index 093429144b..f0eb7645e5 100644 --- a/src/mir_app/src/usedIcons.cpp +++ b/src/mir_app/src/usedIcons.cpp @@ -84,11 +84,10 @@ void RemoveIcon(const char *icolibName) void ResetIcons() { - for (int i = usedIcons.getCount()-1; i >= 0; i--) { - Icon &p = usedIcons[i]; - if (p.refCount <= 0) - usedIcons.remove(i); + for (auto &it : usedIcons.rev_iter()) { + if (it->refCount <= 0) + usedIcons.remove(it); else - p.hImage = INVALID_HANDLE_VALUE; + it->hImage = INVALID_HANDLE_VALUE; } } diff --git a/src/mir_core/src/modules.cpp b/src/mir_core/src/modules.cpp index c410084c65..b78c204aff 100644 --- a/src/mir_core/src/modules.cpp +++ b/src/mir_core/src/modules.cpp @@ -413,18 +413,18 @@ MIR_CORE_DLL(void) KillModuleEventHooks(HINSTANCE hInst) { mir_cslock lck(csHooks); - for (int i = hooks.getCount() - 1; i >= 0; i--) { - if (hooks[i]->subscriberCount == 0) + for (auto &it : hooks.rev_iter()) { + if (it->subscriberCount == 0) continue; - for (int j = hooks[i]->subscriberCount - 1; j >= 0; j--) { - if (hooks[i]->subscriber[j].hOwner != hInst) + for (int j = it->subscriberCount - 1; j >= 0; j--) { + if (it->subscriber[j].hOwner != hInst) continue; char szModuleName[MAX_PATH]; - GetModuleFileNameA(hooks[i]->subscriber[j].hOwner, szModuleName, sizeof(szModuleName)); - UnhookEvent((HANDLE)((hooks[i]->id << 16) + j + 1)); - if (hooks[i]->subscriberCount == 0) + GetModuleFileNameA(it->subscriber[j].hOwner, szModuleName, sizeof(szModuleName)); + UnhookEvent((HANDLE)((it->id << 16) + j + 1)); + if (it->subscriberCount == 0) break; } } @@ -434,14 +434,14 @@ MIR_CORE_DLL(void) KillObjectEventHooks(void* pObject) { mir_cslock lck(csHooks); - for (int i = hooks.getCount() - 1; i >= 0; i--) { - if (hooks[i]->subscriberCount == 0) + for (auto &it : hooks.rev_iter()) { + if (it->subscriberCount == 0) continue; - for (int j = hooks[i]->subscriberCount - 1; j >= 0; j--) { - if (hooks[i]->subscriber[j].object == pObject) { - UnhookEvent((HANDLE)((hooks[i]->id << 16) + j + 1)); - if (hooks[i]->subscriberCount == 0) + for (int j = it->subscriberCount - 1; j >= 0; j--) { + if (it->subscriber[j].object == pObject) { + UnhookEvent((HANDLE)((it->id << 16) + j + 1)); + if (it->subscriberCount == 0) break; } } @@ -452,11 +452,11 @@ static void DestroyHooks() { mir_cslock lck(csHooks); - for (auto &p : hooks) { - if (p->subscriberCount) - mir_free(p->subscriber); - DeleteCriticalSection(&p->csHook); - mir_free(p); + for (auto &it : hooks) { + if (it->subscriberCount) + mir_free(it->subscriber); + DeleteCriticalSection(&it->csHook); + mir_free(it); } } @@ -639,11 +639,11 @@ MIR_CORE_DLL(void) KillModuleServices(HINSTANCE hInst) { mir_cslock lck(csServices); - for (int i = services.getCount() - 1; i >= 0; i--) { - if (services[i]->hOwner == hInst) { + for (auto &it : services.rev_iter()) { + if (it->hOwner == hInst) { char szModuleName[MAX_PATH]; - GetModuleFileNameA(services[i]->hOwner, szModuleName, sizeof(szModuleName)); - DestroyServiceFunction((HANDLE)services[i]->nameHash); + GetModuleFileNameA(it->hOwner, szModuleName, sizeof(szModuleName)); + DestroyServiceFunction((HANDLE)it->nameHash); } } } @@ -652,9 +652,9 @@ MIR_CORE_DLL(void) KillObjectServices(void* pObject) { mir_cslock lck(csServices); - for (int i = services.getCount() - 1; i >= 0; i--) - if (services[i]->object == pObject) - DestroyServiceFunction((HANDLE)services[i]->nameHash); + for (auto &it : services.rev_iter()) + if (it->object == pObject) + DestroyServiceFunction((HANDLE)it->nameHash); } static void DestroyServices() diff --git a/src/mir_core/src/subclass.cpp b/src/mir_core/src/subclass.cpp index c60eba41ad..d64fc3b5fb 100644 --- a/src/mir_core/src/subclass.cpp +++ b/src/mir_core/src/subclass.cpp @@ -179,16 +179,15 @@ MIR_CORE_DLL(LRESULT) mir_callNextSubclass(HWND hWnd, WNDPROC wndProc, UINT uMsg MIR_CORE_DLL(void) KillModuleSubclassing(HMODULE hInst) { - for (int i = arSubclass.getCount() - 1; i >= 0; i--) { - MSubclassData *p = arSubclass[i]; - for (int j = 0; j < p->m_iHooks; j++) { - if (GetInstByAddress(p->m_hooks[j]) == hInst) { - removeHook(p, j); + for (auto &it : arSubclass.rev_iter()) { + for (int j = 0; j < it->m_iHooks; j++) { + if (GetInstByAddress(it->m_hooks[j]) == hInst) { + removeHook(it, j); j--; } } - if (p->m_iHooks == 0) - finalizeSubclassing(p->m_hWnd, p); + if (it->m_iHooks == 0) + finalizeSubclassing(it->m_hWnd, it); } } diff --git a/src/mir_core/src/threads.cpp b/src/mir_core/src/threads.cpp index 120cdeff1e..87a03fc62f 100644 --- a/src/mir_core/src/threads.cpp +++ b/src/mir_core/src/threads.cpp @@ -228,16 +228,15 @@ MIR_CORE_DLL(void) KillObjectThreads(void* owner) if (WaitForMultipleObjects(threadCount, threadPool, TRUE, 5000) == WAIT_TIMEOUT) { // forcibly kill all remaining threads after 5 secs mir_cslock lck(csThreads); - for (int j = threads.getCount() - 1; j >= 0; j--) { - THREAD_WAIT_ENTRY *p = threads[j]; - if (p->pObject == owner) { + for (auto &it : threads.rev_iter()) { + if (it->pObject == owner) { char szModuleName[MAX_PATH]; - GetModuleFileNameA(p->hOwner, szModuleName, sizeof(szModuleName)); - Netlib_Logf(nullptr, "Killing object thread %s:%p", szModuleName, p->dwThreadId); - TerminateThread(p->hThread, 9999); - CloseHandle(p->hThread); - threads.remove(j); - mir_free(p); + GetModuleFileNameA(it->hOwner, szModuleName, sizeof(szModuleName)); + Netlib_Logf(nullptr, "Killing object thread %s:%p", szModuleName, it->dwThreadId); + TerminateThread(it->hThread, 9999); + CloseHandle(it->hThread); + threads.remove(it); + mir_free(it); } } } diff --git a/src/mir_core/src/windowlist.cpp b/src/mir_core/src/windowlist.cpp index a785472cbb..9fe88f5c33 100644 --- a/src/mir_core/src/windowlist.cpp +++ b/src/mir_core/src/windowlist.cpp @@ -89,8 +89,8 @@ MIR_CORE_DLL(int) WindowList_Broadcast(MWindowList hList, UINT message, WPARAM w if (hList == nullptr) return NULL; - for (int i = hList->getCount()-1; i >= 0; i--) - SendMessage((*hList)[i].hWnd, message, wParam, lParam); + for (auto &it : hList->rev_iter()) + SendMessage(it->hWnd, message, wParam, lParam); return 0; } @@ -99,7 +99,7 @@ MIR_CORE_DLL(int) WindowList_BroadcastAsync(MWindowList hList, UINT message, WPA if (hList == nullptr) return NULL; - for (int i = hList->getCount()-1; i >= 0; i--) - PostMessage((*hList)[i].hWnd, message, wParam, lParam); + for (auto &it : hList->rev_iter()) + PostMessage(it->hWnd, message, wParam, lParam); return 0; } -- cgit v1.2.3