mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 803668 - convert string bundle caches to use mozilla::LinkedList; r=smontagu
This commit is contained in:
parent
1039d8f34c
commit
29da20abd2
@ -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;
|
||||
@ -659,7 +650,7 @@ nsStringBundleService::insertIntoCache(nsIStringBundle* aBundle,
|
||||
} 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);
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user