summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGeorge Hazan <ghazan@miranda.im>2018-03-09 19:32:32 +0300
committerGeorge Hazan <ghazan@miranda.im>2018-03-09 19:32:39 +0300
commitdf6b0c988eb26339d4c7e4a1d0fe3b9717703c28 (patch)
tree5b4960edd6c9186e1fbc14f83f7f08a6a842f0a7 /src
parent303dd9297732fc943ed3e20ab37587f0c009dfe5 (diff)
more loop-related code cleaning
Diffstat (limited to 'src')
-rw-r--r--src/core/stdmsg/src/cmdlist.cpp9
-rw-r--r--src/mir_core/src/threads.cpp30
-rw-r--r--src/mir_core/src/windowlist.cpp8
3 files changed, 21 insertions, 26 deletions
diff --git a/src/core/stdmsg/src/cmdlist.cpp b/src/core/stdmsg/src/cmdlist.cpp
index 32e6049de4..3b44e921c9 100644
--- a/src/core/stdmsg/src/cmdlist.cpp
+++ b/src/core/stdmsg/src/cmdlist.cpp
@@ -65,17 +65,16 @@ TMsgQueue* msgQueue_find(MCONTACT hContact, int id)
MCONTACT hMeta = db_mc_getMeta(hContact);
mir_cslockfull lck(csMsgQueue);
- for (int i = 0; i < msgQueue.getCount(); i++) {
- TMsgQueue *item = msgQueue[i];
- if ((item->hContact == hContact || item->hContact == hMeta) && item->id == id) {
- msgQueue.remove(i);
+ for (auto &it : msgQueue) {
+ if ((it->hContact == hContact || it->hContact == hMeta) && it->id == id) {
+ msgQueue.remove(it);
if (!msgQueue.getCount() && timerId) {
KillTimer(nullptr, timerId);
timerId = 0;
}
- return item;
+ return it;
}
}
return nullptr;
diff --git a/src/mir_core/src/threads.cpp b/src/mir_core/src/threads.cpp
index 9d293c2e5e..120cdeff1e 100644
--- a/src/mir_core/src/threads.cpp
+++ b/src/mir_core/src/threads.cpp
@@ -218,11 +218,9 @@ MIR_CORE_DLL(void) KillObjectThreads(void* owner)
{
mir_cslock lck(csThreads);
- for (int j = threads.getCount(); j--;) {
- THREAD_WAIT_ENTRY *p = threads[j];
- if (p->pObject == owner)
- threadPool[threadCount++] = p->hThread;
- }
+ for (auto &it : threads)
+ if (it->pObject == owner)
+ threadPool[threadCount++] = it->hThread;
}
// is there anything to kill?
@@ -250,20 +248,18 @@ MIR_CORE_DLL(void) KillObjectThreads(void* owner)
static void CALLBACK KillAllThreads(HWND, UINT, UINT_PTR, DWORD)
{
- {
- mir_cslock lck(csThreads);
- for (auto &p : threads) {
- char szModuleName[MAX_PATH];
- GetModuleFileNameA(p->hOwner, szModuleName, sizeof(szModuleName));
- Netlib_Logf(nullptr, "Killing thread %s:%p (%p)", szModuleName, p->dwThreadId, p->pEntryPoint);
- TerminateThread(p->hThread, 9999);
- CloseHandle(p->hThread);
- mir_free(p);
- }
-
- threads.destroy();
+ mir_cslock lck(csThreads);
+ for (auto &p : threads) {
+ char szModuleName[MAX_PATH];
+ GetModuleFileNameA(p->hOwner, szModuleName, sizeof(szModuleName));
+ Netlib_Logf(nullptr, "Killing thread %s:%p (%p)", szModuleName, p->dwThreadId, p->pEntryPoint);
+ TerminateThread(p->hThread, 9999);
+ CloseHandle(p->hThread);
+ mir_free(p);
}
+ threads.destroy();
+
SetEvent(hThreadQueueEmpty);
}
diff --git a/src/mir_core/src/windowlist.cpp b/src/mir_core/src/windowlist.cpp
index 13b339b8f6..a785472cbb 100644
--- a/src/mir_core/src/windowlist.cpp
+++ b/src/mir_core/src/windowlist.cpp
@@ -66,12 +66,12 @@ MIR_CORE_DLL(int) WindowList_Remove(MWindowList hList, HWND hwnd)
{
if (hList == nullptr) return 1;
- for (int i = 0; i < hList->getCount(); i++) {
- if ((*hList)[i].hWnd == hwnd) {
- hList->remove(i);
+ for (auto &it : *hList)
+ if (it->hWnd == hwnd) {
+ hList->remove(it);
return 0;
}
- }
+
return 1;
}