summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGeorge Hazan <ghazan@miranda.im>2018-03-15 21:05:06 +0300
committerGeorge Hazan <ghazan@miranda.im>2018-03-15 21:05:06 +0300
commit59e6b15f513cc998ce13e9e49e2a6a3ace445ebb (patch)
treeaf52b73a17039ed1fbe398ba9f488c26a7071257 /src
parentbdaa5cf8b48515af2ac39f3f3245dd1183cbad52 (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
Diffstat (limited to 'src')
-rw-r--r--src/core/stdmsg/src/cmdlist.cpp6
-rw-r--r--src/mir_app/src/extraicons.cpp11
-rw-r--r--src/mir_app/src/hotkey_opts.cpp2
-rw-r--r--src/mir_app/src/hotkeys.cpp4
-rw-r--r--src/mir_app/src/icolib.cpp8
-rw-r--r--src/mir_app/src/meta_services.cpp2
-rw-r--r--src/mir_app/src/newplugins.cpp2
-rw-r--r--src/mir_app/src/options.cpp9
-rw-r--r--src/mir_app/src/proto_accs.cpp2
-rw-r--r--src/mir_app/src/srmm_toolbar.cpp2
-rw-r--r--src/mir_core/src/modules.cpp4
-rw-r--r--src/mir_core/src/threads.cpp2
-rw-r--r--src/mir_core/src/windowlist.cpp2
13 files changed, 26 insertions, 30 deletions
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;
}