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 197905 34473bcef1b75424e6277dbf7328a511bf61c5ff
parent 197904 efb8d769808993e8425a28c15d692cd752334975
child 197906 e70e9419acc226064b3ad6c7737638b064a880a5
push id3624
push userasasaki@mozilla.com
push dateMon, 09 Jun 2014 21:49:01 +0000
treeherdermozilla-beta@b1a5da15899a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersehsan
bugs997963
milestone31.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
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;
 };