Bug 1168007 (part 9) - Use PLDHashTable2 in nsCacheEntry. r=froydnj.

It's not entirely clear if it's necessary to call Clear() in
nsCacheEntryHashTable::Init(). There is lots of inheritance around this code
and the calling patterns of Init() and Shutdown() aren't clear. Better safe
than sorry.

--HG--
extra : rebase_source : e21764b8cbdf7cda7894651e57653e24ac7e1502
This commit is contained in:
Nicholas Nethercote 2015-05-18 21:45:30 -07:00
Родитель a84d4cd609
Коммит f88934c4f6
4 изменённых файлов: 15 добавлений и 14 удалений

10
netwerk/cache/nsCacheEntry.cpp поставляемый
Просмотреть файл

@ -385,7 +385,8 @@ nsCacheEntryHashTable::ops =
nsCacheEntryHashTable::nsCacheEntryHashTable()
: initialized(false)
: table(&ops, sizeof(nsCacheEntryHashTableEntry), kInitialTableLength)
, initialized(false)
{
MOZ_COUNT_CTOR(nsCacheEntryHashTable);
}
@ -399,19 +400,18 @@ nsCacheEntryHashTable::~nsCacheEntryHashTable()
}
nsresult
void
nsCacheEntryHashTable::Init()
{
PL_DHashTableInit(&table, &ops, sizeof(nsCacheEntryHashTableEntry), 256);
table.ClearAndPrepareForLength(kInitialTableLength);
initialized = true;
return NS_OK;
}
void
nsCacheEntryHashTable::Shutdown()
{
if (initialized) {
PL_DHashTableFinish(&table);
table.ClearAndPrepareForLength(kInitialTableLength);
initialized = false;
}
}

10
netwerk/cache/nsCacheEntry.h поставляемый
Просмотреть файл

@ -267,13 +267,13 @@ public:
nsCacheEntryHashTable();
~nsCacheEntryHashTable();
nsresult Init();
void Init();
void Shutdown();
nsCacheEntry *GetEntry( const nsCString * key);
nsresult AddEntry( nsCacheEntry *entry);
void RemoveEntry( nsCacheEntry *entry);
void VisitEntries( PLDHashEnumerator etor, void *arg);
private:
@ -302,11 +302,13 @@ private:
PLDHashEntryHdr * hdr,
uint32_t number,
void * arg);
// member variables
static const PLDHashTableOps ops;
PLDHashTable table;
PLDHashTable2 table;
bool initialized;
static const uint32_t kInitialTableLength = 256;
};
#endif // _nsCacheEntry_h_

3
netwerk/cache/nsCacheService.cpp поставляемый
Просмотреть файл

@ -1153,8 +1153,7 @@ nsCacheService::Init()
}
// initialize hashtable for active cache entries
rv = mActiveEntries.Init();
if (NS_FAILED(rv)) return rv;
mActiveEntries.Init();
// create profile/preference observer
if (!mObserver) {

6
netwerk/cache/nsMemoryCacheDevice.cpp поставляемый
Просмотреть файл

@ -55,9 +55,9 @@ nsMemoryCacheDevice::Init()
{
if (mInitialized) return NS_ERROR_ALREADY_INITIALIZED;
nsresult rv = mMemCacheEntries.Init();
mInitialized = NS_SUCCEEDED(rv);
return rv;
mMemCacheEntries.Init();
mInitialized = true;
return NS_OK;
}