Bug 1163331 - Update /mailnews/ for PLDHashTable API changes. r=rkent
authorNicholas Nethercote <nnethercote@mozilla.com>
Tue, 02 Jun 2015 21:58:46 -0700
changeset 17815 b3a333547c76e1b8bdfe9944d456b657481a332c
parent 17814 4fbe8718e655ae6b1f7d203b9ada1c605bf7c05d
child 17816 e0f36011323e4232f998d6f6cbf8cf5b55cd0949
push id1443
push usermbanner@mozilla.com
push dateMon, 10 Aug 2015 18:31:17 +0000
treeherdercomm-esr52@90a7d0c47f7a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersrkent
bugs1163331
Bug 1163331 - Update /mailnews/ for PLDHashTable API changes. r=rkent
mailnews/db/msgdb/src/nsMsgDatabase.cpp
mailnews/extensions/bayesian-spam-filter/src/nsBayesianFilter.cpp
--- a/mailnews/db/msgdb/src/nsMsgDatabase.cpp
+++ b/mailnews/db/msgdb/src/nsMsgDatabase.cpp
@@ -483,17 +483,17 @@ void nsMsgDatabase::GetGlobalPrefs()
   }
 }
 
 nsresult nsMsgDatabase::AddHdrToCache(nsIMsgDBHdr *hdr, nsMsgKey key) // do we want key? We could get it from hdr
 {
   if (m_bCacheHeaders)
   {
     if (!m_cachedHeaders)
-      m_cachedHeaders = PL_NewDHashTable(&gMsgDBHashTableOps, sizeof(struct MsgHdrHashElement), m_cacheSize);
+      m_cachedHeaders = new PLDHashTable(&gMsgDBHashTableOps, sizeof(struct MsgHdrHashElement), m_cacheSize);
     if (m_cachedHeaders)
     {
       if (key == nsMsgKey_None)
         hdr->GetMessageKey(&key);
       if (m_cachedHeaders->EntryCount() > m_cacheSize)
         ClearHdrCache(true);
       PLDHashEntryHdr *entry = PL_DHashTableAdd(m_cachedHeaders, (void *)(uintptr_t) key, mozilla::fallible);
       if (!entry)
@@ -660,25 +660,22 @@ nsresult nsMsgDatabase::ClearHdrCache(bo
   {
     // save this away in case we renter this code.
     PLDHashTable  *saveCachedHeaders = m_cachedHeaders;
     m_cachedHeaders = nullptr;
     PL_DHashTableEnumerate(saveCachedHeaders, HeaderEnumerator, nullptr);
 
     if (reInit)
     {
-      PL_DHashTableFinish(saveCachedHeaders);
-      PL_DHashTableInit(saveCachedHeaders, &gMsgDBHashTableOps,
-                        sizeof(struct MsgHdrHashElement), m_cacheSize);
+      saveCachedHeaders->ClearAndPrepareForLength(m_cacheSize);
       m_cachedHeaders = saveCachedHeaders;
-
     }
     else
     {
-      PL_DHashTableDestroy(saveCachedHeaders);
+      delete saveCachedHeaders;
     }
   }
   return NS_OK;
 }
 
 nsresult nsMsgDatabase::RemoveHdrFromCache(nsIMsgDBHdr *hdr, nsMsgKey key)
 {
   if (m_cachedHeaders)
@@ -770,17 +767,17 @@ nsMsgDatabase::ClearEntry(PLDHashTable* 
 
 nsresult nsMsgDatabase::AddHdrToUseCache(nsIMsgDBHdr *hdr, nsMsgKey key)
 {
   if (!m_headersInUse)
   {
     mdb_count numHdrs = MSG_HASH_SIZE;
     if (m_mdbAllMsgHeadersTable)
       m_mdbAllMsgHeadersTable->GetCount(GetEnv(), &numHdrs);
-    m_headersInUse = PL_NewDHashTable(&gMsgDBHashTableOps, sizeof(struct MsgHdrHashElement), std::max((mdb_count)MSG_HASH_SIZE, numHdrs));
+    m_headersInUse = new PLDHashTable(&gMsgDBHashTableOps, sizeof(struct MsgHdrHashElement), std::max((mdb_count)MSG_HASH_SIZE, numHdrs));
   }
   if (m_headersInUse)
   {
     if (key == nsMsgKey_None)
       hdr->GetMessageKey(&key);
     PLDHashEntryHdr *entry = PL_DHashTableAdd(m_headersInUse, (void *)(uintptr_t) key, mozilla::fallible);
     if (!entry)
       return NS_ERROR_OUT_OF_MEMORY; // XXX out of memory
@@ -799,17 +796,17 @@ nsresult nsMsgDatabase::AddHdrToUseCache
 
 nsresult nsMsgDatabase::ClearUseHdrCache()
 {
   if (m_headersInUse)
   {
     // clear mdb row pointers of any headers still in use, because the
     // underlying db is going away.
     PL_DHashTableEnumerate(m_headersInUse, ClearHeaderEnumerator, nullptr);
-    PL_DHashTableDestroy(m_headersInUse);
+    delete m_headersInUse;
     m_headersInUse = nullptr;
   }
   return NS_OK;
 }
 
 nsresult nsMsgDatabase::RemoveHdrFromUseCache(nsIMsgDBHdr *hdr, nsMsgKey key)
 {
   if (m_headersInUse)
@@ -1143,17 +1140,17 @@ nsMsgDatabase::~nsMsgDatabase()
   //  Close(FALSE);  // better have already been closed.
   ClearCachedObjects(true);
   ClearEnumerators();
   delete m_cachedHeaders;
   delete m_headersInUse;
 
   if (m_msgReferences)
   {
-    PL_DHashTableDestroy(m_msgReferences);
+    delete m_msgReferences;
     m_msgReferences = nullptr;
   }
 
   PR_LOG(DBLog, PR_LOG_ALWAYS, ("closing database    %s\n",
     (const char*)m_dbName.get()));
 
   nsCOMPtr<nsIMsgDBService> serv(do_GetService(NS_MSGDB_SERVICE_CONTRACTID));
   if (serv)
@@ -4224,20 +4221,20 @@ static nsresult nsReferencesOnlyFilter(n
   msg->GetNumReferences(&numReferences);
   return (numReferences) ? NS_OK : NS_ERROR_FAILURE;
 }
 
 nsresult nsMsgDatabase::InitRefHash()
 {
   // Delete an existing table just in case
   if (m_msgReferences)
-    PL_DHashTableDestroy(m_msgReferences);
+    delete m_msgReferences;
 
   // Create new table
-  m_msgReferences = PL_NewDHashTable(&gRefHashTableOps, sizeof(struct RefHashElement), MSG_HASH_SIZE);
+  m_msgReferences = new PLDHashTable(&gRefHashTableOps, sizeof(struct RefHashElement), MSG_HASH_SIZE);
   if (!m_msgReferences)
     return NS_ERROR_OUT_OF_MEMORY;
 
   // Create enumerator to go through all messages with references
   nsCOMPtr <nsISimpleEnumerator> enumerator;
   enumerator = new nsMsgDBEnumerator(this, m_mdbAllMsgHeadersTable, nsReferencesOnlyFilter, nullptr);
   if (enumerator == nullptr)
     return NS_ERROR_OUT_OF_MEMORY;
--- a/mailnews/extensions/bayesian-spam-filter/src/nsBayesianFilter.cpp
+++ b/mailnews/extensions/bayesian-spam-filter/src/nsBayesianFilter.cpp
@@ -144,35 +144,33 @@ static PLDHashOperator VisitEntry(PLDHas
 static const PLDHashTableOps gTokenTableOps = {
     PL_DHashStringKey,
     PL_DHashMatchStringKey,
     PL_DHashMoveEntryStub,
     PL_DHashClearEntryStub
 };
 
 TokenHash::TokenHash(uint32_t aEntrySize)
+  : mTokenTable(&gTokenTableOps, aEntrySize, 128)
 {
     mEntrySize = aEntrySize;
     PL_INIT_ARENA_POOL(&mWordPool, "Words Arena", 16384);
-    PL_DHashTableInit(&mTokenTable, &gTokenTableOps, aEntrySize, 128);
 }
 
 TokenHash::~TokenHash()
 {
-    PL_DHashTableFinish(&mTokenTable);
     PL_FinishArenaPool(&mWordPool);
 }
 
 nsresult TokenHash::clearTokens()
 {
     // we re-use the tokenizer when classifying multiple messages,
     // so this gets called after every message classification.
-    PL_DHashTableFinish(&mTokenTable);
+    mTokenTable.ClearAndPrepareForLength(128);
     PL_FreeArenaPool(&mWordPool);
-    PL_DHashTableInit(&mTokenTable, &gTokenTableOps, mEntrySize, 128);
     return NS_OK;
 }
 
 char* TokenHash::copyWord(const char* word, uint32_t len)
 {
     void* result;
     uint32_t size = 1 + len;
     PL_ARENA_ALLOCATE(result, &mWordPool, size);