Bug 1041822 - Add LookupOrAdd to nsClassHashtable. r=bsmedberg

This commit is contained in:
Blake Kaplan 2014-08-11 11:13:36 -07:00
Родитель 23294fd2f8
Коммит d0f92bdf21
1 изменённых файлов: 18 добавлений и 0 удалений

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

@ -35,6 +35,13 @@ public:
{
}
/**
* Looks up aKey in the hash table. If it doesn't exist a new object of
* KeyClass will be created (using its default constructor) and then
* returned.
*/
UserDataType LookupOrAdd(KeyType aKey);
/**
* @copydoc nsBaseHashtable::Get
* @param aData if the key doesn't exist, pData will be set to nullptr.
@ -65,6 +72,17 @@ public:
// nsClassHashtable definitions
//
template<class KeyClass, class T>
T*
nsClassHashtable<KeyClass, T>::LookupOrAdd(KeyType aKey)
{
typename base_type::EntryType* ent = this->PutEntry(aKey);
if (!ent->mData) {
ent->mData = new T();
}
return ent->mData;
}
template<class KeyClass, class T>
bool
nsClassHashtable<KeyClass, T>::Get(KeyType aKey, T** aRetVal) const