зеркало из https://github.com/mozilla/pjs.git
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:
Родитель
b25feb8317
Коммит
18c2f1d9a6
|
@ -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);
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
|
Загрузка…
Ссылка в новой задаче