diff options
author | George Hazan <george.hazan@gmail.com> | 2014-03-11 19:31:45 +0000 |
---|---|---|
committer | George Hazan <george.hazan@gmail.com> | 2014-03-11 19:31:45 +0000 |
commit | 29d0fd99991e9deaae5787b4568b407c50630f84 (patch) | |
tree | 66ca2181b7b4840de2b7afb1ff4bdd3578a1325c /src/modules/clist/clistsettings.cpp | |
parent | bd4c78f20e084ccdd20c05d1420c06969bc44925 (diff) |
old nasty perversion with dynamically created lists removed
git-svn-id: http://svn.miranda-ng.org/main/trunk@8562 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'src/modules/clist/clistsettings.cpp')
-rw-r--r-- | src/modules/clist/clistsettings.cpp | 44 |
1 files changed, 14 insertions, 30 deletions
diff --git a/src/modules/clist/clistsettings.cpp b/src/modules/clist/clistsettings.cpp index 196daf1b51..c17e6e0d24 100644 --- a/src/modules/clist/clistsettings.cpp +++ b/src/modules/clist/clistsettings.cpp @@ -25,31 +25,16 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "..\..\core\commonheaders.h"
#include "clc.h"
-SortedList* clistCache = NULL;
-
-static int compareContacts(ClcCacheEntry *p1, ClcCacheEntry *p2)
-{
- return (char*)p1->hContact - (char*)p2->hContact;
-}
-
-void InitDisplayNameCache(void)
-{
- clistCache = List_Create(0, 50);
- clistCache->sortFunc = (FSortFunc)compareContacts;
-}
+static LIST<ClcCacheEntry> clistCache(50, NumericKeySortT);
void FreeDisplayNameCache(void)
{
- if (clistCache != NULL) {
- for (int i=0; i < clistCache->realCount; i++) {
- cli.pfnFreeCacheItem((ClcCacheEntry*)clistCache->items[i]);
- mir_free(clistCache->items[i]);
- }
-
- List_Destroy(clistCache);
- mir_free(clistCache);
- clistCache = NULL;
+ for (int i=0; i < clistCache.getCount(); i++) {
+ cli.pfnFreeCacheItem(clistCache[i]);
+ mir_free(clistCache[i]);
}
+
+ clistCache.destroy();
}
// default handlers for the cache item creation and destruction
@@ -89,14 +74,14 @@ void fnFreeCacheItem(ClcCacheEntry *p) ClcCacheEntry* fnGetCacheEntry(MCONTACT hContact)
{
ClcCacheEntry *p;
- int idx;
- if (!List_GetIndex(clistCache, &hContact, &idx)) {
+ int idx = clistCache.getIndex((ClcCacheEntry*)&hContact);
+ if (idx == -1) {
if ((p = cli.pfnCreateCacheItem(hContact)) != NULL) {
- List_Insert(clistCache, p, idx);
- cli.pfnInvalidateDisplayNameCacheEntry((MCONTACT)p);
+ clistCache.insert(p);
+ cli.pfnInvalidateDisplayNameCacheEntry(hContact);
}
}
- else p = (ClcCacheEntry*)clistCache->items[idx];
+ else p = clistCache[idx];
cli.pfnCheckCacheItem(p);
return p;
@@ -106,13 +91,12 @@ void fnInvalidateDisplayNameCacheEntry(MCONTACT hContact) {
if (hContact == INVALID_CONTACT_ID) {
FreeDisplayNameCache();
- InitDisplayNameCache();
SendMessage(cli.hwndContactTree, CLM_AUTOREBUILD, 0, 0);
}
else {
- int idx;
- if (List_GetIndex(clistCache, &hContact, &idx))
- cli.pfnFreeCacheItem((ClcCacheEntry*)clistCache->items[idx]);
+ int idx = clistCache.getIndex((ClcCacheEntry*)&hContact);
+ if (idx != -1)
+ cli.pfnFreeCacheItem(clistCache[idx]);
}
}
|