summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGeorge Hazan <ghazan@miranda.im>2018-03-15 15:33:54 +0300
committerGeorge Hazan <ghazan@miranda.im>2018-03-15 15:34:09 +0300
commit44b60862c97e5ec855d2bacd4d15f81f7ae7f410 (patch)
treecfe6fd232fac8c80c2f7673804352b94187d698b
parent0a03c7c9ccd36ce03bdb9feb4827314e4dd553c6 (diff)
MUCH more effective way of removing records from iterators
-rw-r--r--include/m_system_cpp.h1
-rw-r--r--plugins/AVS/src/poll.cpp5
-rw-r--r--plugins/Clist_modern/src/modern_aniavatars.cpp5
-rw-r--r--plugins/FavContacts/src/contact_cache.cpp5
-rw-r--r--plugins/HistorySweeperLight/src/historysweeperlight.cpp5
-rw-r--r--plugins/NewXstatusNotify/src/xstatus.cpp15
-rw-r--r--plugins/TabSRMM/src/eventpopups.cpp5
-rw-r--r--plugins/UserInfoEx/src/mir_contactqueue.cpp10
-rw-r--r--protocols/Discord/src/dispatch.cpp5
-rw-r--r--protocols/IcqOscarJ/src/cookies.cpp5
-rw-r--r--src/core/stdmsg/src/cmdlist.cpp5
-rw-r--r--src/mir_app/src/FontService.cpp15
-rw-r--r--src/mir_app/src/chat_manager.cpp5
-rw-r--r--src/mir_app/src/hotkey_opts.cpp13
-rw-r--r--src/mir_app/src/hotkeys.cpp10
-rw-r--r--src/mir_app/src/icolib.cpp5
-rw-r--r--src/mir_app/src/proto_accs.cpp5
-rw-r--r--src/mir_app/src/sounds.cpp5
-rw-r--r--src/mir_app/src/srmm_statusicon.cpp5
-rw-r--r--src/mir_app/src/srmm_toolbar.cpp15
-rw-r--r--src/mir_app/src/usedIcons.cpp5
-rw-r--r--src/mir_core/src/threads.cpp5
22 files changed, 93 insertions, 61 deletions
diff --git a/include/m_system_cpp.h b/include/m_system_cpp.h
index 8b94e15013..729ddcb414 100644
--- a/include/m_system_cpp.h
+++ b/include/m_system_cpp.h
@@ -221,6 +221,7 @@ template<class T> struct LIST
__inline iterator begin() const { return iterator(base + index); }
__inline iterator end() const { return iterator(base-1); }
+ __inline int indexOf(T **p) const { return int(p - base); }
};
__inline void destroy(void) { List_Destroy((SortedList*)this); }
diff --git a/plugins/AVS/src/poll.cpp b/plugins/AVS/src/poll.cpp
index 3ba1bf90a0..940d44f184 100644
--- a/plugins/AVS/src/poll.cpp
+++ b/plugins/AVS/src/poll.cpp
@@ -104,9 +104,10 @@ static void QueueRemove(MCONTACT hContact)
{
mir_cslock lck(cs);
- for (auto &it : queue.rev_iter())
+ auto T = queue.rev_iter();
+ for (auto &it : T)
if (it->hContact == hContact)
- queue.remove(it);
+ queue.remove(T.indexOf(&it));
}
// Add an contact to a queue
diff --git a/plugins/Clist_modern/src/modern_aniavatars.cpp b/plugins/Clist_modern/src/modern_aniavatars.cpp
index bc72629674..c04448b182 100644
--- a/plugins/Clist_modern/src/modern_aniavatars.cpp
+++ b/plugins/Clist_modern/src/modern_aniavatars.cpp
@@ -265,10 +265,11 @@ static void _AniAva_ResumePainting()
static void _AniAva_ReduceAvatarImages(int startY, int dY, BOOL bDestroyWindow)
{
- for (auto &it : s_Objects.rev_iter()) {
+ auto T = s_Objects.rev_iter();
+ for (auto &it : T) {
int res = SendMessage(it->hWindow, AAM_REMOVEAVATAR, (WPARAM)startY, (LPARAM)dY);
if (res == 0xDEAD && bDestroyWindow)
- s_Objects.remove(it);
+ s_Objects.remove(T.indexOf(&it));
}
}
diff --git a/plugins/FavContacts/src/contact_cache.cpp b/plugins/FavContacts/src/contact_cache.cpp
index 5ebd3f1c71..6cf3b37761 100644
--- a/plugins/FavContacts/src/contact_cache.cpp
+++ b/plugins/FavContacts/src/contact_cache.cpp
@@ -38,12 +38,13 @@ int __cdecl CContactCache::OnDbEventAdded(WPARAM hContact, LPARAM hEvent)
TContactInfo *pFound = nullptr;
mir_cslock lck(m_cs);
- for (auto &it : m_cache.rev_iter()) {
+ auto T = m_cache.rev_iter();
+ for (auto &it : T) {
it->rate *= q;
if (it->hContact == hContact) {
it->rate += weight;
pFound = it;
- m_cache.remove(it); // reinsert to maintain the sort order
+ m_cache.remove(T.indexOf(&it)); // reinsert to maintain the sort order
}
}
diff --git a/plugins/HistorySweeperLight/src/historysweeperlight.cpp b/plugins/HistorySweeperLight/src/historysweeperlight.cpp
index 65c37b0196..62a6f3b102 100644
--- a/plugins/HistorySweeperLight/src/historysweeperlight.cpp
+++ b/plugins/HistorySweeperLight/src/historysweeperlight.cpp
@@ -224,9 +224,10 @@ int OnWindowEvent(WPARAM, LPARAM lParam)
SweepHistoryFromContact(msgEvData->hContact, Criteria, TRUE);
}
- for (auto &it : g_hWindows.rev_iter())
+ auto T = g_hWindows.rev_iter();
+ for (auto &it : T)
if (it == PVOID(msgEvData->hContact))
- g_hWindows.remove(it);
+ g_hWindows.remove(T.indexOf(&it));
break;
}
diff --git a/plugins/NewXstatusNotify/src/xstatus.cpp b/plugins/NewXstatusNotify/src/xstatus.cpp
index a582c8e5c7..c15cf4e746 100644
--- a/plugins/NewXstatusNotify/src/xstatus.cpp
+++ b/plugins/NewXstatusNotify/src/xstatus.cpp
@@ -42,30 +42,33 @@ void FreeXSC(XSTATUSCHANGE *xsc)
void RemoveLoggedEventsXStatus(MCONTACT hContact)
{
- for (auto &it : eventListXStatus.rev_iter())
+ auto T = eventListXStatus.rev_iter();
+ for (auto &it : T)
if (it->hContact == hContact) {
db_event_delete(it->hContact, it->hDBEvent);
- eventListXStatus.remove(it);
+ eventListXStatus.remove(T.indexOf(&it));
mir_free(it);
}
}
void RemoveLoggedEventsStatus(MCONTACT hContact)
{
- for (auto &it : eventListStatus.rev_iter())
+ auto T = eventListStatus.rev_iter();
+ for (auto &it : T)
if (it->hContact == hContact) {
db_event_delete(it->hContact, it->hDBEvent);
- eventListStatus.remove(it);
+ eventListStatus.remove(T.indexOf(&it));
mir_free(it);
}
}
void RemoveLoggedEventsSMsg(MCONTACT hContact)
{
- for (auto &it : eventListSMsg.rev_iter())
+ auto T = eventListSMsg.rev_iter();
+ for (auto &it : T)
if (it->hContact == hContact) {
db_event_delete(it->hContact, it->hDBEvent);
- eventListSMsg.remove(it);
+ eventListSMsg.remove(T.indexOf(&it));
mir_free(it);
}
}
diff --git a/plugins/TabSRMM/src/eventpopups.cpp b/plugins/TabSRMM/src/eventpopups.cpp
index b1759de869..8dff9716bb 100644
--- a/plugins/TabSRMM/src/eventpopups.cpp
+++ b/plugins/TabSRMM/src/eventpopups.cpp
@@ -54,13 +54,14 @@ static PLUGIN_DATAT* PU_GetByContact(const MCONTACT hContact)
*/
static void PU_CleanUp()
{
- for (auto &p : arPopupList.rev_iter()) {
+ auto T = arPopupList.rev_iter();
+ for (auto &p : T) {
if (p->hContact != 0)
continue;
mir_free(p->eventData);
mir_free(p);
- arPopupList.remove(p);
+ arPopupList.remove(T.indexOf(&p));
}
}
diff --git a/plugins/UserInfoEx/src/mir_contactqueue.cpp b/plugins/UserInfoEx/src/mir_contactqueue.cpp
index 752a9fbbc5..9ba36425ad 100644
--- a/plugins/UserInfoEx/src/mir_contactqueue.cpp
+++ b/plugins/UserInfoEx/src/mir_contactqueue.cpp
@@ -83,9 +83,10 @@ void CContactQueue::RemoveAll(MCONTACT hContact)
{
mir_cslock lck(_cs);
- for (auto &qi : _queue.rev_iter()) {
+ auto T = _queue.rev_iter();
+ for (auto &qi : T) {
if (qi->hContact == hContact) {
- _queue.remove(qi);
+ _queue.remove(T.indexOf(&qi));
mir_free(qi);
}
}
@@ -98,9 +99,10 @@ void CContactQueue::RemoveAllConsiderParam(MCONTACT hContact, PVOID param)
{
mir_cslock lck(_cs);
- for (auto &qi : _queue.rev_iter())
+ auto T = _queue.rev_iter();
+ for (auto &qi : T)
if (qi->hContact == hContact && qi->param == param) {
- _queue.remove(qi);
+ _queue.remove(T.indexOf(&qi));
mir_free(qi);
}
}
diff --git a/protocols/Discord/src/dispatch.cpp b/protocols/Discord/src/dispatch.cpp
index be99ebf054..33cf2fe556 100644
--- a/protocols/Discord/src/dispatch.cpp
+++ b/protocols/Discord/src/dispatch.cpp
@@ -194,10 +194,11 @@ void CDiscordProto::OnCommandGuildDeleted(const JSONNode &pRoot)
if (pGuild == nullptr)
return;
- for (auto &it : arUsers.rev_iter())
+ auto T = arUsers.rev_iter();
+ for (auto &it : T)
if (it->guildId == pGuild->id) {
Chat_Terminate(m_szModuleName, it->wszUsername, true);
- arUsers.remove(it);
+ arUsers.remove(T.indexOf(&it));
}
Chat_Terminate(m_szModuleName, pRoot["name"].as_mstring(), true);
diff --git a/protocols/IcqOscarJ/src/cookies.cpp b/protocols/IcqOscarJ/src/cookies.cpp
index de73d58e03..a517f93923 100644
--- a/protocols/IcqOscarJ/src/cookies.cpp
+++ b/protocols/IcqOscarJ/src/cookies.cpp
@@ -33,9 +33,10 @@ void CIcqProto::RemoveExpiredCookies()
{
time_t tNow = time(nullptr);
- for (auto &it : cookies.rev_iter())
+ auto T = cookies.rev_iter();
+ for (auto &it : T)
if (it->dwTime + COOKIE_TIMEOUT < tNow)
- cookies.remove(it);
+ cookies.remove(T.indexOf(&it));
}
// Generate and allocate cookie
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);
}
}