Bug 419036 - "Simplify nsCacheEntryHashTable::VisitEntries and break 'friendship'" [p=alfredkayser@gmail.com (Alfred Kayser) r=dcamp sr=biesi a1.9=damons]

This commit is contained in:
reed@reedloden.com 2008-03-11 01:08:05 -07:00
parent 74d8a4f62e
commit fc7cc13805
4 changed files with 14 additions and 42 deletions

View File

@ -488,25 +488,14 @@ nsCacheEntryHashTable::RemoveEntry( nsCacheEntry *cacheEntry)
void
nsCacheEntryHashTable::VisitEntries( nsCacheEntryHashTable::Visitor *visitor)
nsCacheEntryHashTable::VisitEntries( PLDHashEnumerator etor, void *arg)
{
NS_ASSERTION(initialized, "nsCacheEntryHashTable not initialized");
if (!initialized) return; // NS_ERROR_NOT_INITIALIZED
PL_DHashTableEnumerate(&table, VisitEntry, visitor);
PL_DHashTableEnumerate(&table, etor, arg);
}
PLDHashOperator PR_CALLBACK
nsCacheEntryHashTable::VisitEntry(PLDHashTable *table,
PLDHashEntryHdr *hashEntry,
PRUint32 number,
void *arg)
{
nsCacheEntry *cacheEntry = ((nsCacheEntryHashTableEntry *)hashEntry)->cacheEntry;
nsCacheEntryHashTable::Visitor *visitor = (nsCacheEntryHashTable::Visitor*) arg;
return (visitor->VisitEntry(cacheEntry) ? PL_DHASH_NEXT : PL_DHASH_STOP);
}
/**
* hash table operation callback functions
*/

View File

@ -295,17 +295,9 @@ public:
nsresult AddEntry( nsCacheEntry *entry);
void RemoveEntry( nsCacheEntry *entry);
// XXX enumerate entries?
class Visitor {
public:
virtual PRBool VisitEntry( nsCacheEntry *entry) = 0;
};
void VisitEntries( Visitor *visitor);
private:
friend class nsCacheService; // XXX redefine interface so this isn't necessary
void VisitEntries( PLDHashEnumerator etor, void *arg);
private:
// PLDHashTable operation callbacks
static PLDHashNumber PR_CALLBACK HashKey( PLDHashTable *table, const void *key);

View File

@ -2139,8 +2139,7 @@ nsCacheService::ClearDoomList()
void
nsCacheService::ClearActiveEntries()
{
// XXX really we want a different finalize callback for mActiveEntries
PL_DHashTableEnumerate(&mActiveEntries.table, DeactivateAndClearEntry, nsnull);
mActiveEntries.VisitEntries(DeactivateAndClearEntry, nsnull);
mActiveEntries.Shutdown();
}
@ -2168,7 +2167,7 @@ nsCacheService::DoomActiveEntries()
{
nsAutoVoidArray array;
PL_DHashTableEnumerate(&mActiveEntries.table, RemoveActiveEntry, &array);
mActiveEntries.VisitEntries(RemoveActiveEntry, &array);
PRUint32 count = array.Count();
for (PRUint32 i=0; i < count; ++i)

View File

@ -472,22 +472,14 @@ nsMemoryCacheDevice::SetCapacity(PRInt32 capacity)
#ifdef DEBUG
class nsCacheHashCounter : public nsCacheEntryHashTable::Visitor {
public:
nsCacheHashCounter() : entryCount(0) {}
PRBool VisitEntry(nsCacheEntry * entry);
PRInt32 entryCount;
};
PRBool nsCacheHashCounter::VisitEntry(nsCacheEntry * entry)
static PLDHashOperator PR_CALLBACK
CountEntry(PLDHashTable * table, PLDHashEntryHdr * hdr, PRUint32 number, void * arg)
{
++entryCount;
return PR_TRUE;
PRInt32 *entryCount = (PRInt32 *)arg;
++(*entryCount);
return PL_DHASH_NEXT;
}
void
nsMemoryCacheDevice::CheckEntryCount()
{
@ -503,9 +495,9 @@ nsMemoryCacheDevice::CheckEntryCount()
}
NS_ASSERTION(mEntryCount == evictionListCount, "### mem cache badness");
nsCacheHashCounter hash;
mMemCacheEntries.VisitEntries(&hash);
NS_ASSERTION(mEntryCount == hash.entryCount, "### mem cache badness");
PRInt32 entryCount = 0;
mMemCacheEntries.VisitEntries(CountEntry, &entryCount);
NS_ASSERTION(mEntryCount == entryCount, "### mem cache badness");
}
#endif