From 831890a8024a9519cdf725c5a098898734e54e93 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Tue, 25 Feb 2014 21:19:01 +0000 Subject: metacontacts in the database cache git-svn-id: http://svn.miranda-ng.org/main/trunk@8276 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- src/modules/database/mdatabasecache.cpp | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) (limited to 'src/modules/database/mdatabasecache.cpp') diff --git a/src/modules/database/mdatabasecache.cpp b/src/modules/database/mdatabasecache.cpp index 1dcd29861e..2a2812515d 100644 --- a/src/modules/database/mdatabasecache.cpp +++ b/src/modules/database/mdatabasecache.cpp @@ -24,12 +24,12 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "..\..\core\commonheaders.h" #include "database.h" -static int stringCompare(const char* p1, const char* p2) +static int stringCompare(const char *p1, const char *p2) { return strcmp(p1, p2); } -static int compareGlobals(const DBCachedGlobalValue* p1, const DBCachedGlobalValue* p2) +static int compareGlobals(const DBCachedGlobalValue *p1, const DBCachedGlobalValue *p2) { return strcmp(p1->name, p2->name); } @@ -56,14 +56,14 @@ DBCachedContact* MDatabaseCache::AddContactToCache(MCONTACT contactID) mir_cslock lck(m_cs); int index = m_lContacts.getIndex((DBCachedContact*)&contactID); - if (index == -1) { - DBCachedContact* VL = (DBCachedContact*)HeapAlloc(m_hCacheHeap, HEAP_ZERO_MEMORY, sizeof(DBCachedContact)); - VL->contactID = contactID; - m_lContacts.insert(VL); - return VL; - } - - return m_lContacts[index]; + if (index != -1) + return m_lContacts[index]; + + DBCachedContact *cc = (DBCachedContact*)HeapAlloc(m_hCacheHeap, HEAP_ZERO_MEMORY, sizeof(DBCachedContact)); + cc->contactID = contactID; + cc->nSubs = -1; + m_lContacts.insert(cc); + return cc; } DBCachedContact* MDatabaseCache::GetCachedContact(MCONTACT contactID) @@ -96,15 +96,17 @@ void MDatabaseCache::FreeCachedContact(MCONTACT contactID) if (index == -1) return; - DBCachedContact* VL = m_lContacts[index]; - DBCachedContactValue* V = VL->first; + DBCachedContact *cc = m_lContacts[index]; + DBCachedContactValue* V = cc->first; while (V != NULL) { DBCachedContactValue* V1 = V->next; FreeCachedVariant(&V->value); HeapFree(m_hCacheHeap, 0, V); V = V1; } - HeapFree(m_hCacheHeap, 0, VL); + + free(cc->pSubs); + HeapFree(m_hCacheHeap, 0, cc); m_lContacts.remove(index); } -- cgit v1.2.3