mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-02-21 09:49:14 +00:00
Bug 1291707 part 2 - Add GetAndRemove to nsDataHashtable. r=froydnj
MozReview-Commit-ID: 24zlYwsRGsF --HG-- extra : rebase_source : 904c62cd779133666904d3167cb7e7c31f95a412 extra : source : 6c1df15aad607e70547b51011bd352d8a8bf826d
This commit is contained in:
parent
a0c0bf51d9
commit
fab96c1410
@ -9,6 +9,7 @@
|
||||
|
||||
#include "nsHashKeys.h"
|
||||
#include "nsBaseHashtable.h"
|
||||
#include "mozilla/Maybe.h"
|
||||
|
||||
/**
|
||||
* templated hashtable class maps keys to simple datatypes.
|
||||
@ -22,12 +23,36 @@ template<class KeyClass, class DataType>
|
||||
class nsDataHashtable
|
||||
: public nsBaseHashtable<KeyClass, DataType, DataType>
|
||||
{
|
||||
private:
|
||||
typedef nsBaseHashtable<KeyClass, DataType, DataType> BaseClass;
|
||||
|
||||
public:
|
||||
using typename BaseClass::KeyType;
|
||||
using typename BaseClass::EntryType;
|
||||
|
||||
nsDataHashtable() {}
|
||||
explicit nsDataHashtable(uint32_t aInitLength)
|
||||
: nsBaseHashtable<KeyClass, DataType, DataType>(aInitLength)
|
||||
: BaseClass(aInitLength)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the value for a key and remove the corresponding entry at
|
||||
* the same time.
|
||||
*
|
||||
* @param aKey the key to retrieve and remove
|
||||
* @return the found value, or Nothing if no entry was found with the
|
||||
* given key.
|
||||
*/
|
||||
mozilla::Maybe<DataType> GetAndRemove(KeyType aKey)
|
||||
{
|
||||
mozilla::Maybe<DataType> value;
|
||||
if (EntryType* ent = this->GetEntry(aKey)) {
|
||||
value.emplace(mozilla::Move(ent->mData));
|
||||
this->RemoveEntry(ent);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
};
|
||||
|
||||
#endif // nsDataHashtable_h__
|
||||
|
Loading…
x
Reference in New Issue
Block a user