summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGeorge Hazan <ghazan@miranda.im>2018-03-09 14:04:19 +0300
committerGeorge Hazan <ghazan@miranda.im>2018-03-09 14:04:19 +0300
commit2d594691c91bf8ed3c1d3339333379a9356b4156 (patch)
tree73b5a70ef4f49f65acaf5cd1f9eb5bfadbca895f /src
parent3e3526a52e25abfec0598f305cbc6d8b0049567b (diff)
fix for another over-optimiized loop
Diffstat (limited to 'src')
-rw-r--r--src/mir_app/src/clistevents.cpp99
1 files changed, 49 insertions, 50 deletions
diff --git a/src/mir_app/src/clistevents.cpp b/src/mir_app/src/clistevents.cpp
index ecb73ea2eb..4a0edc1a89 100644
--- a/src/mir_app/src/clistevents.cpp
+++ b/src/mir_app/src/clistevents.cpp
@@ -260,68 +260,67 @@ int fnEventsProcessTrayDoubleClick(int index)
if (g_cliEvents.getCount() == 0)
return 1;
- int eventIndex = 0;
-
- mir_cslockfull lck(trayLockCS);
- if (cli.trayIconCount > 1 && index > 0) {
- int i;
- char *szProto = nullptr;
- for (i = 0; i < cli.trayIconCount; i++) {
- if (cli.trayIcon[i].id == index) {
- szProto = cli.trayIcon[i].szProto;
- if (i == 0)
- click_in_first_icon = TRUE;
- break;
- }
- }
- if (szProto) {
- for (auto &it : g_cliEvents) {
- char *eventProto = nullptr;
- if (it->hContact)
- eventProto = GetContactProto(it->hContact);
- if (!eventProto)
- eventProto = it->lpszProtocol;
-
- if (!eventProto || !_strcmpi(eventProto, szProto)) {
- eventIndex = i;
+ CListEvent *pEvent = nullptr;
+ {
+ mir_cslock lck(trayLockCS);
+ if (cli.trayIconCount > 1 && index > 0) {
+ char *szProto = nullptr;
+ for (int i = 0; i < cli.trayIconCount; i++) {
+ if (cli.trayIcon[i].id == index) {
+ szProto = cli.trayIcon[i].szProto;
+ if (i == 0)
+ click_in_first_icon = TRUE;
break;
}
}
+ if (szProto) {
+ for (auto &it : g_cliEvents) {
+ char *eventProto = nullptr;
+ if (it->hContact)
+ eventProto = GetContactProto(it->hContact);
+ if (!eventProto)
+ eventProto = it->lpszProtocol;
+
+ if (!eventProto || !_strcmpi(eventProto, szProto)) {
+ pEvent = it;
+ break;
+ }
+ }
- // let's process backward try to find first event without desired proto in tray
- if (i == g_cliEvents.getCount()) {
- if (click_in_first_icon) {
- for (auto &it : g_cliEvents) {
- char *eventProto = nullptr;
- if (it->hContact)
- eventProto = GetContactProto(it->hContact);
- if (!eventProto)
- eventProto = it->lpszProtocol;
- if (!eventProto)
- continue;
-
- int j;
- for (j = 0; j < cli.trayIconCount; j++)
- if (cli.trayIcon[j].szProto && !_strcmpi(eventProto, cli.trayIcon[j].szProto))
+ // let's process backward try to find first event without desired proto in tray
+ if (pEvent == nullptr) {
+ if (click_in_first_icon) {
+ for (auto &it : g_cliEvents) {
+ char *eventProto = nullptr;
+ if (it->hContact)
+ eventProto = GetContactProto(it->hContact);
+ if (!eventProto)
+ eventProto = it->lpszProtocol;
+ if (!eventProto)
+ continue;
+
+ int j;
+ for (j = 0; j < cli.trayIconCount; j++)
+ if (cli.trayIcon[j].szProto && !_strcmpi(eventProto, cli.trayIcon[j].szProto))
+ break;
+
+ if (j == cli.trayIconCount) {
+ pEvent = it;
break;
-
- if (j == cli.trayIconCount) {
- eventIndex = i;
- break;
+ }
}
}
+ if (pEvent == nullptr) //not found
+ return 1; //continue processing to show contact list
}
- if (i == g_cliEvents.getCount()) //not found
- return 1; //continue processing to show contact list
}
}
}
- lck.unlock();
- MCONTACT hContact = g_cliEvents[eventIndex].hContact;
- MEVENT hDbEvent = g_cliEvents[eventIndex].hDbEvent;
- // ; may be better to show send msg?
- CallService(g_cliEvents[eventIndex].pszService, 0, (LPARAM)&g_cliEvents[eventIndex]);
+ // copy info in case that events' array could be shifted by the service call
+ MCONTACT hContact = pEvent->hContact;
+ MEVENT hDbEvent = pEvent->hDbEvent;
+ CallService(pEvent->pszService, 0, (LPARAM)pEvent);
cli.pfnRemoveEvent(hContact, hDbEvent);
return 0;
}