Adding nsHashtable::Reset(). Changing nsObjectHashtable destructor to use Reset instead of enumerate. This will cause hash entires to be removed from the hash table as values in the hash table are released.

This commit is contained in:
dp%netscape.com 1999-07-31 05:41:54 +00:00
Родитель b25feb8317
Коммит 18c2f1d9a6
2 изменённых файлов: 23 добавлений и 3 удалений

Просмотреть файл

@ -216,11 +216,30 @@ void nsHashtable::Enumerate(nsHashtableEnumFunc aEnumFunc, void* closure) {
static PR_CALLBACK PRIntn _hashEnumerateRemove(PLHashEntry *he, PRIntn i, void *arg)
{
return HT_ENUMERATE_REMOVE;
_HashEnumerateArgs* thunk = (_HashEnumerateArgs*)arg;
if (thunk)
return thunk->fn((nsHashKey *) he->key, he->value, thunk->arg)
? HT_ENUMERATE_REMOVE
: HT_ENUMERATE_STOP;
else
return HT_ENUMERATE_REMOVE;
}
void nsHashtable::Reset() {
PL_HashTableEnumerateEntries(hashtable, _hashEnumerateRemove, NULL);
Reset(NULL);
}
void nsHashtable::Reset(nsHashtableEnumFunc destroyFunc, void* closure)
{
if (destroyFunc != NULL)
{
_HashEnumerateArgs thunk;
thunk.fn = destroyFunc;
thunk.arg = closure;
PL_HashTableEnumerateEntries(hashtable, _hashEnumerateRemove, &thunk);
}
else
PL_HashTableEnumerateEntries(hashtable, _hashEnumerateRemove, NULL);
}
////////////////////////////////////////////////////////////////////////////////
@ -300,7 +319,7 @@ nsObjectHashtable::nsObjectHashtable(nsHashtableCloneElementFunc cloneElementFun
nsObjectHashtable::~nsObjectHashtable()
{
Enumerate(mDestroyElementFun, mDestroyElementClosure);
Reset(mDestroyElementFun, mDestroyElementClosure);
}
PR_CALLBACK PRIntn

Просмотреть файл

@ -55,6 +55,7 @@ public:
nsHashtable *Clone();
void Enumerate(nsHashtableEnumFunc aEnumFunc, void* closure = NULL);
void Reset();
void Reset(nsHashtableEnumFunc destroyFunc, void* closure = NULL);
};
////////////////////////////////////////////////////////////////////////////////