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:
Trevor Saunders 2016-11-08 15:54:45 -05:00
Родитель 85a8fbb70f
Коммит 93e1959ffb
1 изменённых файлов: 16 добавлений и 0 удалений

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

@ -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