зеркало из https://github.com/mozilla/gecko-dev.git
bug 1316119 - add a GetOrInsert to nsBaseHashtable that returns a reference to the value r=froydnj
This intends to expose basically the same functionality as operator[] on unordered_map.
This commit is contained in:
Родитель
85a8fbb70f
Коммит
93e1959ffb
|
@ -115,6 +115,22 @@ public:
|
|||
return ent->mData;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add key to the table if not already present, and return a reference to its
|
||||
* value. If key is not already in the table then the value is default
|
||||
* constructed.
|
||||
*/
|
||||
DataType& GetOrInsert(const KeyType& aKey)
|
||||
{
|
||||
EntryType* ent = this->GetEntry(aKey);
|
||||
if (ent) {
|
||||
return ent->mData;
|
||||
}
|
||||
|
||||
ent = this->PutEntry(aKey);
|
||||
return ent->mData;
|
||||
}
|
||||
|
||||
/**
|
||||
* put a new value for the associated key
|
||||
* @param aKey the key to put
|
||||
|
|
Загрузка…
Ссылка в новой задаче