mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-10 03:45:46 +00:00
Bug 1175771 (part 3) - Replace nsCacheEntryHashable::VisitEntries() with iterators. r=michal.
Note that FreeCacheEntries was unused, and so could be removed as well. --HG-- extra : rebase_source : 9b34399dc79479b47935b89c21c0525d010127c1
This commit is contained in:
parent
4ce0a4d3ed
commit
2599e0384d
14
netwerk/cache/nsCacheEntry.cpp
vendored
14
netwerk/cache/nsCacheEntry.cpp
vendored
@ -462,15 +462,17 @@ nsCacheEntryHashTable::RemoveEntry( nsCacheEntry *cacheEntry)
|
||||
PL_DHashTableRemove(&table, &(cacheEntry->mKey));
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
nsCacheEntryHashTable::VisitEntries( PLDHashEnumerator etor, void *arg)
|
||||
PLDHashTable::Iterator
|
||||
nsCacheEntryHashTable::Iter() const
|
||||
{
|
||||
NS_ASSERTION(initialized, "nsCacheEntryHashTable not initialized");
|
||||
if (!initialized) return; // NS_ERROR_NOT_INITIALIZED
|
||||
PL_DHashTableEnumerate(&table, etor, arg);
|
||||
return PLDHashTable::Iterator(&table);
|
||||
}
|
||||
|
||||
PLDHashTable::RemovingIterator
|
||||
nsCacheEntryHashTable::RemovingIter()
|
||||
{
|
||||
return PLDHashTable::RemovingIterator(&table);
|
||||
}
|
||||
|
||||
/**
|
||||
* hash table operation callback functions
|
||||
|
22
netwerk/cache/nsCacheEntry.h
vendored
22
netwerk/cache/nsCacheEntry.h
vendored
@ -255,11 +255,11 @@ private:
|
||||
/******************************************************************************
|
||||
* nsCacheEntryHashTable
|
||||
*******************************************************************************/
|
||||
typedef struct {
|
||||
PLDHashNumber keyHash;
|
||||
nsCacheEntry *cacheEntry;
|
||||
} nsCacheEntryHashTableEntry;
|
||||
|
||||
struct nsCacheEntryHashTableEntry : public PLDHashEntryHdr
|
||||
{
|
||||
nsCacheEntry *cacheEntry;
|
||||
};
|
||||
|
||||
class nsCacheEntryHashTable
|
||||
{
|
||||
@ -274,7 +274,8 @@ public:
|
||||
nsresult AddEntry( nsCacheEntry *entry);
|
||||
void RemoveEntry( nsCacheEntry *entry);
|
||||
|
||||
void VisitEntries( PLDHashEnumerator etor, void *arg);
|
||||
PLDHashTable::Iterator Iter() const;
|
||||
PLDHashTable::RemovingIterator RemovingIter();
|
||||
|
||||
private:
|
||||
// PLDHashTable operation callbacks
|
||||
@ -292,17 +293,6 @@ private:
|
||||
|
||||
static void Finalize( PLDHashTable *table);
|
||||
|
||||
static
|
||||
PLDHashOperator FreeCacheEntries(PLDHashTable * table,
|
||||
PLDHashEntryHdr * hdr,
|
||||
uint32_t number,
|
||||
void * arg);
|
||||
static
|
||||
PLDHashOperator VisitEntry(PLDHashTable * table,
|
||||
PLDHashEntryHdr * hdr,
|
||||
uint32_t number,
|
||||
void * arg);
|
||||
|
||||
// member variables
|
||||
static const PLDHashTableOps ops;
|
||||
PLDHashTable table;
|
||||
|
63
netwerk/cache/nsCacheService.cpp
vendored
63
netwerk/cache/nsCacheService.cpp
vendored
@ -2914,58 +2914,32 @@ nsCacheService::ClearDoomList()
|
||||
}
|
||||
}
|
||||
|
||||
PLDHashOperator
|
||||
nsCacheService::GetActiveEntries(PLDHashTable * table,
|
||||
PLDHashEntryHdr * hdr,
|
||||
uint32_t number,
|
||||
void * arg)
|
||||
{
|
||||
static_cast<nsTArray<nsCacheEntry*>*>(arg)->AppendElement(
|
||||
((nsCacheEntryHashTableEntry *)hdr)->cacheEntry);
|
||||
return PL_DHASH_NEXT;
|
||||
}
|
||||
|
||||
struct ActiveEntryArgs
|
||||
{
|
||||
nsTArray<nsCacheEntry*>* mActiveArray;
|
||||
nsCacheService::DoomCheckFn mCheckFn;
|
||||
};
|
||||
|
||||
void
|
||||
nsCacheService::DoomActiveEntries(DoomCheckFn check)
|
||||
{
|
||||
nsAutoTArray<nsCacheEntry*, 8> array;
|
||||
ActiveEntryArgs args = { &array, check };
|
||||
|
||||
mActiveEntries.VisitEntries(RemoveActiveEntry, &args);
|
||||
for (auto iter = mActiveEntries.RemovingIter(); !iter.Done(); iter.Next()) {
|
||||
nsCacheEntry* entry =
|
||||
static_cast<nsCacheEntryHashTableEntry*>(iter.Get())->cacheEntry;
|
||||
|
||||
if (check && !check(entry)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
array.AppendElement(entry);
|
||||
|
||||
// entry is being removed from the active entry list
|
||||
entry->MarkInactive();
|
||||
iter.Remove();
|
||||
}
|
||||
|
||||
uint32_t count = array.Length();
|
||||
for (uint32_t i=0; i < count; ++i)
|
||||
for (uint32_t i = 0; i < count; ++i) {
|
||||
DoomEntry_Internal(array[i], true);
|
||||
}
|
||||
}
|
||||
|
||||
PLDHashOperator
|
||||
nsCacheService::RemoveActiveEntry(PLDHashTable * table,
|
||||
PLDHashEntryHdr * hdr,
|
||||
uint32_t number,
|
||||
void * arg)
|
||||
{
|
||||
nsCacheEntry * entry = ((nsCacheEntryHashTableEntry *)hdr)->cacheEntry;
|
||||
NS_ASSERTION(entry, "### active entry = nullptr!");
|
||||
|
||||
ActiveEntryArgs* args = static_cast<ActiveEntryArgs*>(arg);
|
||||
if (args->mCheckFn && !args->mCheckFn(entry))
|
||||
return PL_DHASH_NEXT;
|
||||
|
||||
NS_ASSERTION(args->mActiveArray, "### array = nullptr!");
|
||||
args->mActiveArray->AppendElement(entry);
|
||||
|
||||
// entry is being removed from the active entry list
|
||||
entry->MarkInactive();
|
||||
return PL_DHASH_REMOVE; // and continue enumerating
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
nsCacheService::CloseAllStreams()
|
||||
{
|
||||
@ -2979,7 +2953,10 @@ nsCacheService::CloseAllStreams()
|
||||
|
||||
#if DEBUG
|
||||
// make sure there is no active entry
|
||||
mActiveEntries.VisitEntries(GetActiveEntries, &entries);
|
||||
for (auto iter = mActiveEntries.Iter(); !iter.Done(); iter.Next()) {
|
||||
auto entry = static_cast<nsCacheEntryHashTableEntry*>(iter.Get());
|
||||
entries.AppendElement(entry->cacheEntry);
|
||||
}
|
||||
NS_ASSERTION(entries.IsEmpty(), "Bad state");
|
||||
#endif
|
||||
|
||||
|
11
netwerk/cache/nsCacheService.h
vendored
11
netwerk/cache/nsCacheService.h
vendored
@ -310,17 +310,6 @@ private:
|
||||
void CloseAllStreams();
|
||||
void FireClearNetworkCacheStoredAnywhereNotification();
|
||||
|
||||
static
|
||||
PLDHashOperator GetActiveEntries(PLDHashTable * table,
|
||||
PLDHashEntryHdr * hdr,
|
||||
uint32_t number,
|
||||
void * arg);
|
||||
static
|
||||
PLDHashOperator RemoveActiveEntry(PLDHashTable * table,
|
||||
PLDHashEntryHdr * hdr,
|
||||
uint32_t number,
|
||||
void * arg);
|
||||
|
||||
static
|
||||
PLDHashOperator ShutdownCustomCacheDeviceEnum(const nsAString& aProfileDir,
|
||||
nsRefPtr<nsOfflineCacheDevice>& aDevice,
|
||||
|
14
netwerk/cache/nsMemoryCacheDevice.cpp
vendored
14
netwerk/cache/nsMemoryCacheDevice.cpp
vendored
@ -529,14 +529,6 @@ nsMemoryCacheDevice::SetMaxEntrySize(int32_t maxSizeInKilobytes)
|
||||
}
|
||||
|
||||
#ifdef DEBUG
|
||||
static PLDHashOperator
|
||||
CountEntry(PLDHashTable * table, PLDHashEntryHdr * hdr, uint32_t number, void * arg)
|
||||
{
|
||||
int32_t *entryCount = (int32_t *)arg;
|
||||
++(*entryCount);
|
||||
return PL_DHASH_NEXT;
|
||||
}
|
||||
|
||||
void
|
||||
nsMemoryCacheDevice::CheckEntryCount()
|
||||
{
|
||||
@ -553,8 +545,10 @@ nsMemoryCacheDevice::CheckEntryCount()
|
||||
NS_ASSERTION(mEntryCount == evictionListCount, "### mem cache badness");
|
||||
|
||||
int32_t entryCount = 0;
|
||||
mMemCacheEntries.VisitEntries(CountEntry, &entryCount);
|
||||
NS_ASSERTION(mEntryCount == entryCount, "### mem cache badness");
|
||||
for (auto iter = mMemCacheEntries.Iter(); !iter.Done(); iter.Next()) {
|
||||
++entryCount;
|
||||
}
|
||||
NS_ASSERTION(mEntryCount == entryCount, "### mem cache badness");
|
||||
}
|
||||
#endif
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user