Bug 803668 - convert string bundle caches to use mozilla::LinkedList; r=smontagu

This commit is contained in:
Nathan Froyd 2012-11-01 10:03:41 -04:00
parent 589f3dc93b
commit dd8473fad8
2 changed files with 11 additions and 19 deletions

View File

@ -501,8 +501,7 @@ nsresult nsExtensibleStringBundle::GetSimpleEnumeration(nsISimpleEnumerator ** a
#define MAX_CACHED_BUNDLES 16
struct bundleCacheEntry_t {
PRCList list;
struct bundleCacheEntry_t : public LinkedListElement<bundleCacheEntry_t> {
nsCStringKey *mHashKey;
// do not use a nsCOMPtr - this is a struct not a class!
nsIStringBundle* mBundle;
@ -516,7 +515,6 @@ nsStringBundleService::nsStringBundleService() :
printf("\n++ nsStringBundleService::nsStringBundleService ++\n");
#endif
PR_INIT_CLIST(&mBundleCache);
PL_InitArenaPool(&mCacheEntryPool, "srEntries",
sizeof(bundleCacheEntry_t)*MAX_CACHED_BUNDLES,
sizeof(bundleCacheEntry_t));
@ -582,16 +580,10 @@ nsStringBundleService::flushBundleCache()
// release all bundles in the cache
mBundleMap.Reset();
PRCList *current = PR_LIST_HEAD(&mBundleCache);
while (current != &mBundleCache) {
bundleCacheEntry_t *cacheEntry = (bundleCacheEntry_t*)current;
while (!mBundleCache.isEmpty()) {
bundleCacheEntry_t *cacheEntry = mBundleCache.popFirst();
recycleEntry(cacheEntry);
PRCList *oldItem = current;
current = PR_NEXT_LINK(current);
// will be freed in PL_FreeArenaPool
PR_REMOVE_LINK(oldItem);
}
PL_FreeArenaPool(&mCacheEntryPool);
}
@ -616,7 +608,7 @@ nsStringBundleService::getStringBundle(const char *aURLSpec,
// cache hit!
// remove it from the list, it will later be reinserted
// at the head of the list
PR_REMOVE_LINK((PRCList*)cacheEntry);
cacheEntry->remove();
} else {
@ -633,8 +625,7 @@ nsStringBundleService::getStringBundle(const char *aURLSpec,
// 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
PR_INSERT_LINK((PRCList *)cacheEntry, &mBundleCache);
mBundleCache.insertFront(cacheEntry);
// finally, return the value
*aResult = cacheEntry->mBundle;
@ -654,12 +645,12 @@ nsStringBundleService::insertIntoCache(nsIStringBundle* aBundle,
void *cacheEntryArena;
PL_ARENA_ALLOCATE(cacheEntryArena, &mCacheEntryPool, sizeof(bundleCacheEntry_t));
cacheEntry = (bundleCacheEntry_t*)cacheEntryArena;
cacheEntry = new (cacheEntryArena) bundleCacheEntry_t();
} else {
// cache is full
// take the last entry in the list, and recycle it.
cacheEntry = (bundleCacheEntry_t*)PR_LIST_TAIL(&mBundleCache);
cacheEntry = mBundleCache.getLast();
// remove it from the hash table and linked list
NS_ASSERTION(mBundleMap.Exists(cacheEntry->mHashKey),
@ -670,7 +661,7 @@ nsStringBundleService::insertIntoCache(nsIStringBundle* aBundle,
aHashKey->GetString()).get());
#endif
mBundleMap.Remove(cacheEntry->mHashKey);
PR_REMOVE_LINK((PRCList*)cacheEntry);
cacheEntry->remove();
// free up excess memory
recycleEntry(cacheEntry);

View File

@ -6,7 +6,6 @@
#ifndef nsStringBundleService_h__
#define nsStringBundleService_h__
#include "prclist.h"
#include "plarena.h"
#include "nsCOMPtr.h"
@ -18,6 +17,8 @@
#include "nsIErrorService.h"
#include "nsIStringBundleOverride.h"
#include "mozilla/LinkedList.h"
struct bundleCacheEntry_t;
class nsStringBundleService : public nsIStringBundleService,
@ -48,7 +49,7 @@ private:
static void recycleEntry(bundleCacheEntry_t*);
nsHashtable mBundleMap;
PRCList mBundleCache;
mozilla::LinkedList<bundleCacheEntry_t> mBundleCache;
PLArenaPool mCacheEntryPool;
nsCOMPtr<nsIErrorService> mErrorService;