Bug 997963, part 4 - Turn bundleCacheEntry_t::mBundle into an nsCOMPtr. r=ehsan
authorAndrew McCreight <continuation@gmail.com>
Mon, 21 Apr 2014 09:41:57 -0700
changeset 179813 b7694e60758e8feaf4700285307b449722f4f441
parent 179812 29173518f045ec4da474a50c6c2b6e7f08d87638
child 179814 efb8d769808993e8425a28c15d692cd752334975
push id272
push userpvanderbeken@mozilla.com
push dateMon, 05 May 2014 16:31:18 +0000
reviewersehsan
bugs997963
milestone31.0a1
Bug 997963, part 4 - Turn bundleCacheEntry_t::mBundle into an nsCOMPtr. r=ehsan Also remove the now useless recycleEntry.
intl/strres/src/nsStringBundle.cpp
intl/strres/src/nsStringBundleService.h
--- a/intl/strres/src/nsStringBundle.cpp
+++ b/intl/strres/src/nsStringBundle.cpp
@@ -484,18 +484,17 @@ nsresult nsExtensibleStringBundle::GetSi
 }
 
 /////////////////////////////////////////////////////////////////////////////////////////
 
 #define MAX_CACHED_BUNDLES 16
 
 struct bundleCacheEntry_t : public LinkedListElement<bundleCacheEntry_t> {
   nsAutoPtr<nsCStringKey> mHashKey;
-  // do not use a nsCOMPtr - this is a struct not a class!
-  nsIStringBundle* mBundle;
+  nsCOMPtr<nsIStringBundle> mBundle;
 };
 
 
 nsStringBundleService::nsStringBundleService() :
   mBundleMap(MAX_CACHED_BUNDLES, true)
 {
 #ifdef DEBUG_tao_
   printf("\n++ nsStringBundleService::nsStringBundleService ++\n");
@@ -556,19 +555,17 @@ nsStringBundleService::Observe(nsISuppor
 
 void
 nsStringBundleService::flushBundleCache()
 {
   // release all bundles in the cache
   mBundleMap.Reset();
 
   while (!mBundleCache.isEmpty()) {
-    bundleCacheEntry_t *cacheEntry = mBundleCache.popFirst();
-    recycleEntry(cacheEntry);
-    delete cacheEntry;
+    delete mBundleCache.popFirst();
   }
 }
 
 NS_IMETHODIMP
 nsStringBundleService::FlushBundles()
 {
   flushBundleCache();
   return NS_OK;
@@ -632,40 +629,29 @@ nsStringBundleService::insertIntoCache(n
                  "Element will not be removed!");
 #ifdef DEBUG_alecf
     NS_WARNING(nsPrintfCString("Booting %s to make room for %s\n",
                                cacheEntry->mHashKey->GetString(),
                                aHashKey->GetString()).get());
 #endif
     mBundleMap.Remove(cacheEntry->mHashKey);
     cacheEntry->remove();
-
-    // free up excess memory
-    recycleEntry(cacheEntry);
   }
 
   // at this point we have a new cacheEntry that doesn't exist
   // in the hashtable, so set up the cacheEntry
+  cacheEntry->mHashKey = (nsCStringKey*)aHashKey->Clone();
   cacheEntry->mBundle = aBundle;
-  NS_ADDREF(cacheEntry->mBundle);
-
-  cacheEntry->mHashKey = (nsCStringKey*)aHashKey->Clone();
 
   // insert the entry into the cache and map, make it the MRU
   mBundleMap.Put(cacheEntry->mHashKey, cacheEntry);
 
   return cacheEntry;
 }
 
-void
-nsStringBundleService::recycleEntry(bundleCacheEntry_t *aEntry)
-{
-  NS_RELEASE(aEntry->mBundle);
-}
-
 NS_IMETHODIMP
 nsStringBundleService::CreateBundle(const char* aURLSpec,
                                     nsIStringBundle** aResult)
 {
 #ifdef DEBUG_tao_
   printf("\n++ nsStringBundleService::CreateBundle ++\n");
   printf("\n** nsStringBundleService::CreateBundle: %s\n", aURLSpec ? aURLSpec : "null");
 #endif
--- a/intl/strres/src/nsStringBundleService.h
+++ b/intl/strres/src/nsStringBundleService.h
@@ -39,18 +39,16 @@ private:
                             uint32_t argCount, char16_t** argArray,
                             char16_t* *result);
 
   void flushBundleCache();
 
   bundleCacheEntry_t *insertIntoCache(nsIStringBundle *aBundle,
                                       nsCStringKey *aHashKey);
 
-  static void recycleEntry(bundleCacheEntry_t*);
-
   nsHashtable mBundleMap;
   mozilla::LinkedList<bundleCacheEntry_t> mBundleCache;
 
   nsCOMPtr<nsIErrorService>     mErrorService;
   nsCOMPtr<nsIStringBundleOverride> mOverrideStrings;
 };
 
 #endif