diff options
author | George Hazan <ghazan@miranda.im> | 2018-03-15 15:33:54 +0300 |
---|---|---|
committer | George Hazan <ghazan@miranda.im> | 2018-03-15 15:34:09 +0300 |
commit | 44b60862c97e5ec855d2bacd4d15f81f7ae7f410 (patch) | |
tree | cfe6fd232fac8c80c2f7673804352b94187d698b /src | |
parent | 0a03c7c9ccd36ce03bdb9feb4827314e4dd553c6 (diff) |
MUCH more effective way of removing records from iterators
Diffstat (limited to 'src')
-rw-r--r-- | src/core/stdmsg/src/cmdlist.cpp | 5 | ||||
-rw-r--r-- | src/mir_app/src/FontService.cpp | 15 | ||||
-rw-r--r-- | src/mir_app/src/chat_manager.cpp | 5 | ||||
-rw-r--r-- | src/mir_app/src/hotkey_opts.cpp | 13 | ||||
-rw-r--r-- | src/mir_app/src/hotkeys.cpp | 10 | ||||
-rw-r--r-- | src/mir_app/src/icolib.cpp | 5 | ||||
-rw-r--r-- | src/mir_app/src/proto_accs.cpp | 5 | ||||
-rw-r--r-- | src/mir_app/src/sounds.cpp | 5 | ||||
-rw-r--r-- | src/mir_app/src/srmm_statusicon.cpp | 5 | ||||
-rw-r--r-- | src/mir_app/src/srmm_toolbar.cpp | 15 | ||||
-rw-r--r-- | src/mir_app/src/usedIcons.cpp | 5 | ||||
-rw-r--r-- | src/mir_core/src/threads.cpp | 5 |
12 files changed, 56 insertions, 37 deletions
diff --git a/src/core/stdmsg/src/cmdlist.cpp b/src/core/stdmsg/src/cmdlist.cpp index 23c6fbe20b..2b6c17fe5f 100644 --- a/src/core/stdmsg/src/cmdlist.cpp +++ b/src/core/stdmsg/src/cmdlist.cpp @@ -32,10 +32,11 @@ static VOID CALLBACK MsgTimer(HWND, UINT, UINT_PTR, DWORD dwTime) LIST<TMsgQueue> arTimedOut(1);
{
mir_cslock lck(csMsgQueue);
- for (auto &it : msgQueue.rev_iter())
+ auto T = msgQueue.rev_iter();
+ for (auto &it : T)
if (dwTime - it->ts > g_dat.msgTimeout) {
arTimedOut.insert(it);
- msgQueue.remove(it);
+ msgQueue.remove(T.indexOf(&it));
}
}
diff --git a/src/mir_app/src/FontService.cpp b/src/mir_app/src/FontService.cpp index 58e3caede1..8e07db3829 100644 --- a/src/mir_app/src/FontService.cpp +++ b/src/mir_app/src/FontService.cpp @@ -326,9 +326,10 @@ static INT_PTR ReloadFonts(WPARAM, LPARAM) MIR_APP_DLL(void) KillModuleFonts(int _hLang)
{
- for (auto &it : font_id_list.rev_iter())
+ auto T = font_id_list.rev_iter();
+ for (auto &it : T)
if (it->hLangpack == _hLang)
- font_id_list.remove(it);
+ font_id_list.remove(T.indexOf(&it));
}
/////////////////////////////////////////////////////////////////////////////////////////
@@ -401,9 +402,10 @@ static INT_PTR ReloadColours(WPARAM, LPARAM) MIR_APP_DLL(void) KillModuleColours(int _hLang)
{
- for (auto &it : colour_id_list.rev_iter())
+ auto T = colour_id_list.rev_iter();
+ for (auto &it : T)
if (it->hLangpack == _hLang)
- colour_id_list.remove(it);
+ colour_id_list.remove(T.indexOf(&it));
}
//////////////////////////////////////////////////////////////////////////
@@ -484,9 +486,10 @@ MIR_APP_DLL(int) Effect_Get(const char *szGroup, const char *szName, FONTEFFECT MIR_APP_DLL(void) KillModuleEffects(int _hLang)
{
- for (auto &it : effect_id_list.rev_iter())
+ auto T = colour_id_list.rev_iter();
+ for (auto &it : T)
if (it->hLangpack == _hLang)
- effect_id_list.remove(it);
+ effect_id_list.remove(T.indexOf(&it));
}
/////////////////////////////////////////////////////////////////////////////////////////
diff --git a/src/mir_app/src/chat_manager.cpp b/src/mir_app/src/chat_manager.cpp index bf97ad42b1..0feb9f65b7 100644 --- a/src/mir_app/src/chat_manager.cpp +++ b/src/mir_app/src/chat_manager.cpp @@ -136,10 +136,11 @@ int SM_RemoveSession(const wchar_t *pszID, const char *pszModule, bool removeCon return TRUE;
}
- for (auto &si : g_arSessions.rev_iter()) {
+ auto T = g_arSessions.rev_iter();
+ for (auto &si : T) {
if (si->iType != GCW_SERVER && !mir_strcmpi(si->pszModule, pszModule)) {
SM_FreeSession(si, removeContact);
- g_arSessions.remove(si);
+ g_arSessions.remove(T.indexOf(&si));
}
}
return TRUE;
diff --git a/src/mir_app/src/hotkey_opts.cpp b/src/mir_app/src/hotkey_opts.cpp index b09a7e0944..80d30e2531 100644 --- a/src/mir_app/src/hotkey_opts.cpp +++ b/src/mir_app/src/hotkey_opts.cpp @@ -754,12 +754,15 @@ static INT_PTR CALLBACK sttOptionsDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam, break; UnregisterHotkeys(); - - 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); + { + 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); + } } + } 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 36016bdd59..4c3eabbcdf 100644 --- a/src/mir_app/src/hotkeys.cpp +++ b/src/mir_app/src/hotkeys.cpp @@ -220,9 +220,10 @@ MIR_APP_DLL(int) Hotkey_Unregister(const char *pszName) if (g_hwndHkOptions)
SendMessage(g_hwndHkOptions, WM_HOTKEYUNREGISTERED, 0, 0);
- for (auto &it : hotkeys.rev_iter())
+ auto T = hotkeys.rev_iter();
+ for (auto &it : T)
if (it->UnregisterHotkey) {
- hotkeys.remove(it);
+ hotkeys.remove(T.indexOf(&it));
FreeHotkey(it);
}
@@ -287,9 +288,10 @@ void RegisterHotkeys() MIR_APP_DLL(void) KillModuleHotkeys(int _hLang)
{
- for (auto &it : hotkeys.rev_iter())
+ auto T = hotkeys.rev_iter();
+ for (auto &it : T)
if (it->hLangpack == _hLang) {
- hotkeys.remove(it);
+ hotkeys.remove(T.indexOf(&it));
FreeHotkey(it);
}
}
diff --git a/src/mir_app/src/icolib.cpp b/src/mir_app/src/icolib.cpp index 27d49a1dc6..131df93618 100644 --- a/src/mir_app/src/icolib.cpp +++ b/src/mir_app/src/icolib.cpp @@ -598,9 +598,10 @@ MIR_APP_DLL(void) KillModuleIcons(int _hLang) return;
mir_cslock lck(csIconList);
- for (auto &it : iconList.rev_iter())
+ auto T = iconList.rev_iter();
+ for (auto &it : T)
if (it->hLangpack == _hLang) {
- iconList.remove(it);
+ iconList.remove(T.indexOf(&it));
delete it;
}
}
diff --git a/src/mir_app/src/proto_accs.cpp b/src/mir_app/src/proto_accs.cpp index ad1896e29d..187a4212b1 100644 --- a/src/mir_app/src/proto_accs.cpp +++ b/src/mir_app/src/proto_accs.cpp @@ -402,8 +402,9 @@ void UnloadAccountsModule() {
if (!bModuleInitialized) return;
- for (auto &it : accounts.rev_iter()) {
- accounts.remove(it);
+ auto T = accounts.rev_iter();
+ for (auto &it : T) {
+ accounts.remove(T.indexOf(&it));
UnloadAccount(it, false, false);
}
accounts.destroy();
diff --git a/src/mir_app/src/sounds.cpp b/src/mir_app/src/sounds.cpp index 27128138cf..d6f5147ef1 100644 --- a/src/mir_app/src/sounds.cpp +++ b/src/mir_app/src/sounds.cpp @@ -49,9 +49,10 @@ static OBJLIST<SoundItem> arSounds(10, CompareSounds); MIR_APP_DLL(void) KillModuleSounds(int _hLang)
{
- for (auto &it : arSounds.rev_iter())
+ auto T = arSounds.rev_iter();
+ for (auto &it : T)
if (it->hLangpack == _hLang)
- arSounds.remove(it);
+ arSounds.remove(T.indexOf(&it));
}
/////////////////////////////////////////////////////////////////////////////////////////
diff --git a/src/mir_app/src/srmm_statusicon.cpp b/src/mir_app/src/srmm_statusicon.cpp index c30d3d3ec0..87a83542d9 100644 --- a/src/mir_app/src/srmm_statusicon.cpp +++ b/src/mir_app/src/srmm_statusicon.cpp @@ -197,9 +197,10 @@ MIR_APP_DLL(StatusIconData*) Srmm_GetNthIcon(MCONTACT hContact, int index) void KillModuleSrmmIcons(int _hLang)
{
- for (auto &it : arIcons.rev_iter())
+ auto T = arIcons.rev_iter();
+ for (auto &it : T)
if (it->hLangpack == _hLang)
- arIcons.remove(it);
+ arIcons.remove(T.indexOf(&it));
}
int LoadSrmmModule()
diff --git a/src/mir_app/src/srmm_toolbar.cpp b/src/mir_app/src/srmm_toolbar.cpp index d3b0d7c278..b0ba74df6d 100644 --- a/src/mir_app/src/srmm_toolbar.cpp +++ b/src/mir_app/src/srmm_toolbar.cpp @@ -220,10 +220,11 @@ MIR_APP_DLL(int) Srmm_RemoveButton(BBButton *bbdi) { mir_cslock lck(csToolBar); - for (auto &cbd : arButtonsList.rev_iter()) + auto T = arButtonsList.rev_iter(); + for (auto &cbd : T) if (!mir_strcmp(cbd->m_pszModuleName, bbdi->pszModuleName) && cbd->m_dwButtonID == bbdi->dwButtonID) { pFound = cbd; - arButtonsList.remove(cbd); + arButtonsList.remove(T.indexOf(&cbd)); } } @@ -422,12 +423,13 @@ MIR_APP_DLL(void) Srmm_RedrawToolbarIcons(HWND hwndDlg) static void CB_ReInitCustomButtons() { - for (auto &cbd : arButtonsList.rev_iter()) { + auto T = arButtonsList.rev_iter(); + for (auto &cbd : T) { if (cbd->m_opFlags & (BBSF_NTBSWAPED | BBSF_NTBDESTRUCT)) { cbd->m_opFlags ^= BBSF_NTBSWAPED; if (cbd->m_opFlags & BBSF_NTBDESTRUCT) - arButtonsList.remove(cbd); + arButtonsList.remove(T.indexOf(&cbd)); } } qsort(arButtonsList.getArray(), arButtonsList.getCount(), sizeof(void*), sstSortButtons); @@ -781,9 +783,10 @@ static int SrmmOptionsInit(WPARAM wParam, LPARAM) void KillModuleToolbarIcons(int _hLang) { - for (auto &cbd : arButtonsList.rev_iter()) + auto T = arButtonsList.rev_iter(); + for (auto &cbd : T) if (cbd->m_hLangpack == _hLang) { - arButtonsList.remove(cbd); + arButtonsList.remove(T.indexOf(&cbd)); delete cbd; } } diff --git a/src/mir_app/src/usedIcons.cpp b/src/mir_app/src/usedIcons.cpp index f0eb7645e5..243832196f 100644 --- a/src/mir_app/src/usedIcons.cpp +++ b/src/mir_app/src/usedIcons.cpp @@ -84,9 +84,10 @@ void RemoveIcon(const char *icolibName) void ResetIcons()
{
- for (auto &it : usedIcons.rev_iter()) {
+ auto T = usedIcons.rev_iter();
+ for (auto &it : T) {
if (it->refCount <= 0)
- usedIcons.remove(it);
+ usedIcons.remove(T.indexOf(&it));
else
it->hImage = INVALID_HANDLE_VALUE;
}
diff --git a/src/mir_core/src/threads.cpp b/src/mir_core/src/threads.cpp index 87a03fc62f..5be6150a91 100644 --- a/src/mir_core/src/threads.cpp +++ b/src/mir_core/src/threads.cpp @@ -228,14 +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 (auto &it : threads.rev_iter()) {
+ auto T = threads.rev_iter();
+ for (auto &it : T) {
if (it->pObject == owner) {
char szModuleName[MAX_PATH];
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);
+ threads.remove(T.indexOf(&it));
mir_free(it);
}
}
|