From 8b53cbae6e56c389c4c72088fa24dc22ec569bf9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20P=C3=B6sel?= Date: Wed, 28 Oct 2015 08:32:04 +0000 Subject: Variables: Optimize weird insides of contactSettingChanged() function git-svn-id: http://svn.miranda-ng.org/main/trunk@15632 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- plugins/Variables/src/contact.cpp | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/plugins/Variables/src/contact.cpp b/plugins/Variables/src/contact.cpp index a61b0524d0..995a4ce610 100644 --- a/plugins/Variables/src/contact.cpp +++ b/plugins/Variables/src/contact.cpp @@ -359,23 +359,31 @@ static int contactSettingChanged(WPARAM hContact, LPARAM lParam) { DBCONTACTWRITESETTING *dbw = (DBCONTACTWRITESETTING*)lParam; + char *szProto = GetContactProto(hContact); + if (szProto == NULL) + return 0; + + char *uid = (char*)CallProtoService(szProto, PS_GETCAPS, PFLAG_UNIQUEIDSETTING, 0); + + bool isNick = !strcmp(dbw->szSetting, "Nick"); + bool isFirstName = !strcmp(dbw->szSetting, "FirstName"); + bool isLastName = !strcmp(dbw->szSetting, "LastName"); + bool isEmail = !strcmp(dbw->szSetting, "e-mail"); + bool isMyHandle = !strcmp(dbw->szSetting, "MyHandle"); + bool isUid = (((INT_PTR)uid != CALLSERVICE_NOTFOUND) && (uid != NULL)) && (!strcmp(dbw->szSetting, uid)); + mir_cslock lck(csContactCache); for (int i = 0; i < cacheSize; i++) { if (hContact != cce[i].hContact && (cce[i].flags & CI_CNFINFO) == 0) continue; - - char *szProto = GetContactProto(hContact); - if (szProto == NULL) - continue; - - char *uid = (char*)CallProtoService(szProto, PS_GETCAPS, PFLAG_UNIQUEIDSETTING, 0); - if (((!strcmp(dbw->szSetting, "Nick")) && (cce[i].flags & CI_NICK)) || - ((!strcmp(dbw->szSetting, "FirstName")) && (cce[i].flags & CI_FIRSTNAME)) || - ((!strcmp(dbw->szSetting, "LastName")) && (cce[i].flags & CI_LASTNAME)) || - ((!strcmp(dbw->szSetting, "e-mail")) && (cce[i].flags & CI_EMAIL)) || - ((!strcmp(dbw->szSetting, "MyHandle")) && (cce[i].flags & CI_LISTNAME)) || + + if ((isNick && (cce[i].flags & CI_NICK)) || + (isFirstName && (cce[i].flags & CI_FIRSTNAME)) || + (isLastName && (cce[i].flags & CI_LASTNAME)) || + (isEmail && (cce[i].flags & CI_EMAIL)) || + (isMyHandle && (cce[i].flags & CI_LISTNAME)) || (cce[i].flags & CI_CNFINFO) != 0 || // lazy; always invalidate CNF info cache entries - ((((INT_PTR)uid != CALLSERVICE_NOTFOUND) && (uid != NULL)) && (!strcmp(dbw->szSetting, uid)) && (cce[i].flags & CI_UNIQUEID))) { + (isUid && (cce[i].flags & CI_UNIQUEID))) { /* remove from cache */ mir_free(cce[i].tszContact); if (cacheSize > 1) { -- cgit v1.2.3