зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1041822 - Add LookupOrAdd to nsClassHashtable. r=bsmedberg
This commit is contained in:
Родитель
23294fd2f8
Коммит
d0f92bdf21
|
@ -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
|
||||
|
|
Загрузка…
Ссылка в новой задаче