Bug 997963, part 6 - Use a refptr in nsStringBundleService::getStringBundle. r=ehsan
authorAndrew McCreight <continuation@gmail.com>
Mon, 21 Apr 2014 09:41:57 -0700
changeset 179815 34473bcef1b75424e6277dbf7328a511bf61c5ff
parent 179814 efb8d769808993e8425a28c15d692cd752334975
child 179816 e70e9419acc226064b3ad6c7737638b064a880a5
push id272
push userpvanderbeken@mozilla.com
push dateMon, 05 May 2014 16:31:18 +0000
reviewersehsan
bugs997963
milestone31.0a1
Bug 997963, part 6 - Use a refptr in nsStringBundleService::getStringBundle. r=ehsan
intl/strres/src/nsStringBundle.cpp
intl/strres/src/nsStringBundleService.h
--- a/intl/strres/src/nsStringBundle.cpp
+++ b/intl/strres/src/nsStringBundle.cpp
@@ -584,38 +584,34 @@ nsStringBundleService::getStringBundle(c
     // cache hit!
     // remove it from the list, it will later be reinserted
     // at the head of the list
     cacheEntry->remove();
 
   } else {
 
     // hasn't been cached, so insert it into the hash table
-    nsStringBundle* bundle = new nsStringBundle(aURLSpec, mOverrideStrings);
-    NS_ADDREF(bundle);
-
-    cacheEntry = insertIntoCache(bundle, &completeKey);
-    NS_RELEASE(bundle);         // cache should now be holding a ref
-                                // in the cacheEntry
+    nsRefPtr<nsStringBundle> bundle = new nsStringBundle(aURLSpec, mOverrideStrings);
+    cacheEntry = insertIntoCache(bundle.forget(), &completeKey);
   }
 
   // at this point the cacheEntry should exist in the hashtable,
   // but is not in the LRU cache.
   // put the cache entry at the front of the list
   mBundleCache.insertFront(cacheEntry);
 
   // finally, return the value
   *aResult = cacheEntry->mBundle;
   NS_ADDREF(*aResult);
 
   return NS_OK;
 }
 
 bundleCacheEntry_t *
-nsStringBundleService::insertIntoCache(nsIStringBundle* aBundle,
+nsStringBundleService::insertIntoCache(already_AddRefed<nsIStringBundle> aBundle,
                                        nsCStringKey* aHashKey)
 {
   bundleCacheEntry_t *cacheEntry;
 
   if (mBundleMap.Count() < MAX_CACHED_BUNDLES) {
     // cache not full - create a new entry
     cacheEntry = new bundleCacheEntry_t();
   } else {
--- a/intl/strres/src/nsStringBundleService.h
+++ b/intl/strres/src/nsStringBundleService.h
@@ -36,17 +36,17 @@ public:
 private:
   nsresult getStringBundle(const char *aUrl, nsIStringBundle** aResult);
   nsresult FormatWithBundle(nsIStringBundle* bundle, nsresult aStatus,
                             uint32_t argCount, char16_t** argArray,
                             char16_t* *result);
 
   void flushBundleCache();
 
-  bundleCacheEntry_t *insertIntoCache(nsIStringBundle *aBundle,
+  bundleCacheEntry_t *insertIntoCache(already_AddRefed<nsIStringBundle> aBundle,
                                       nsCStringKey *aHashKey);
 
   nsHashtable mBundleMap;
   mozilla::LinkedList<bundleCacheEntry_t> mBundleCache;
 
   nsCOMPtr<nsIErrorService>     mErrorService;
   nsCOMPtr<nsIStringBundleOverride> mOverrideStrings;
 };