mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-28 23:31:56 +00:00
Bug 1370632 - Move LookupRemoveIf() to nsBaseHashtable instead so that it can be used on more hashtables types. r=froydnj
MozReview-Commit-ID: 9kQSytPWok5
This commit is contained in:
parent
7dd909a5ce
commit
6467c38383
@ -164,6 +164,41 @@ public:
|
||||
*/
|
||||
void Remove(KeyType aKey) { this->RemoveEntry(aKey); }
|
||||
|
||||
/**
|
||||
* Looks up aKey in the hashtable and if found calls the given callback
|
||||
* aFunction with the value. If the callback returns true then the entry
|
||||
* is removed. If aKey doesn't exist nothing happens.
|
||||
* The hashtable must not be modified in the callback function.
|
||||
*
|
||||
* A typical usage of this API looks like this:
|
||||
*
|
||||
* table.LookupRemoveIf(key, [](T* aValue) {
|
||||
* // ... do stuff using aValue ...
|
||||
* return aValue->IsEmpty(); // or some other condition to remove it
|
||||
* });
|
||||
*
|
||||
* This is useful for cases where you want to lookup and possibly modify
|
||||
* the value and then maybe remove the entry but would like to avoid two
|
||||
* hashtable lookups.
|
||||
*/
|
||||
template<class F>
|
||||
void LookupRemoveIf(KeyType aKey, F aFunction)
|
||||
{
|
||||
#ifdef DEBUG
|
||||
auto tableGeneration = GetGeneration();
|
||||
#endif
|
||||
EntryType* ent = this->GetEntry(aKey);
|
||||
if (!ent) {
|
||||
return;
|
||||
}
|
||||
bool shouldRemove = aFunction(ent->mData);
|
||||
MOZ_ASSERT(tableGeneration == GetGeneration(),
|
||||
"hashtable was modified by the LookupRemoveIf callback!");
|
||||
if (shouldRemove) {
|
||||
this->RemoveEntry(ent);
|
||||
}
|
||||
}
|
||||
|
||||
// This is an iterator that also allows entry removal. Example usage:
|
||||
//
|
||||
// for (auto iter = table.Iter(); !iter.Done(); iter.Next()) {
|
||||
|
@ -136,41 +136,6 @@ public:
|
||||
* lookups.
|
||||
*/
|
||||
MOZ_MUST_USE EntryPtr LookupForAdd(KeyType aKey);
|
||||
|
||||
/**
|
||||
* Looks up aKey in the hashtable and if found calls the given callback
|
||||
* aFunction with the value. If the callback returns true then the entry
|
||||
* is removed. If aKey doesn't exist nothing happens.
|
||||
* The hashtable must not be modified in the callback function.
|
||||
*
|
||||
* A typical usage of this API looks like this:
|
||||
*
|
||||
* table.LookupRemoveIf(key, [](T* aValue) {
|
||||
* // ... do stuff using aValue ...
|
||||
* return aValue->IsEmpty(); // or some other condition to remove it
|
||||
* });
|
||||
*
|
||||
* This is useful for cases where you want to lookup and possibly modify
|
||||
* the value and then maybe remove the entry but would like to avoid two
|
||||
* hashtable lookups.
|
||||
*/
|
||||
template<class F>
|
||||
void LookupRemoveIf(KeyType aKey, F aFunction)
|
||||
{
|
||||
#ifdef DEBUG
|
||||
auto tableGeneration = base_type::GetGeneration();
|
||||
#endif
|
||||
typename base_type::EntryType* ent = this->GetEntry(aKey);
|
||||
if (!ent) {
|
||||
return;
|
||||
}
|
||||
bool shouldRemove = aFunction(ent->mData);
|
||||
MOZ_ASSERT(tableGeneration == base_type::GetGeneration(),
|
||||
"hashtable was modified by the LookupRemoveIf callback!");
|
||||
if (shouldRemove) {
|
||||
this->RemoveEntry(ent);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
//
|
||||
|
Loading…
Reference in New Issue
Block a user