From 1a694bbb3a2c8faf3667a3d3bdec9e79541b4e30 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Mon, 12 Mar 2018 15:27:38 +0300 Subject: cycle optimization --- src/mir_app/src/clistevents.cpp | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) (limited to 'src') diff --git a/src/mir_app/src/clistevents.cpp b/src/mir_app/src/clistevents.cpp index b0046fad9a..5f9a566f44 100644 --- a/src/mir_app/src/clistevents.cpp +++ b/src/mir_app/src/clistevents.cpp @@ -38,7 +38,7 @@ static int iconsOn; static int disableTrayFlash; static int disableIconFlash; -OBJLIST g_cliEvents(10); +OBJLIST g_cliEvents(10, PtrKeySortT); int fnGetImlIconIndex(HICON hIcon) { @@ -176,28 +176,29 @@ CListEvent* fnAddEvent(CLISTEVENT *cle) int fnRemoveEvent(MCONTACT hContact, MEVENT dbEvent) { // Find the event that should be removed - int i; - for (i = 0; i < g_cliEvents.getCount(); i++) { - CListEvent &e = g_cliEvents[i]; - if (e.hContact == hContact && e.hDbEvent == dbEvent) + CListEvent *pEvent = nullptr; + for (auto &it : g_cliEvents) { + if (it->hContact == hContact && it->hDbEvent == dbEvent) { + pEvent = it; break; + } } // Event was not found - if (i == g_cliEvents.getCount()) + if (pEvent == nullptr) return 1; // Update contact's icon char *szProto = GetContactProto(hContact); - cli.pfnChangeContactIcon(g_cliEvents[i].hContact, cli.pfnGetContactIcon(g_cliEvents[i].hContact)); + cli.pfnChangeContactIcon(pEvent->hContact, cli.pfnGetContactIcon(pEvent->hContact)); // Free any memory allocated to the event - g_cliEvents.remove(i); + g_cliEvents.remove(pEvent); // count same protocoled events int nSameProto = 0; - char *szEventProto; for (auto &it : g_cliEvents) { + char *szEventProto; if (it->hContact) szEventProto = GetContactProto((it->hContact)); else if (it->flags & CLEF_PROTOCOLGLOBAL) -- cgit v1.2.3