mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-02-21 09:49:14 +00:00
Bug 1290524: Allow nsClassHashTable::LookupOrAdd to provide arguments to construct the new object.
MozReview-Commit-ID: 1s1ZaFWLrri
This commit is contained in:
parent
220e36cb8d
commit
4d812b8ba1
@ -39,10 +39,10 @@ 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.
|
||||
* KeyClass will be created (using the arguments provided) and then returned.
|
||||
*/
|
||||
UserDataType LookupOrAdd(KeyType aKey);
|
||||
template<typename... Args>
|
||||
UserDataType LookupOrAdd(KeyType aKey, Args&&... aConstructionArgs);
|
||||
|
||||
/**
|
||||
* @copydoc nsBaseHashtable::Get
|
||||
@ -75,12 +75,14 @@ public:
|
||||
//
|
||||
|
||||
template<class KeyClass, class T>
|
||||
template<typename... Args>
|
||||
T*
|
||||
nsClassHashtable<KeyClass, T>::LookupOrAdd(KeyType aKey)
|
||||
nsClassHashtable<KeyClass, T>::LookupOrAdd(KeyType aKey,
|
||||
Args&&... aConstructionArgs)
|
||||
{
|
||||
typename base_type::EntryType* ent = this->PutEntry(aKey);
|
||||
if (!ent->mData) {
|
||||
ent->mData = new T();
|
||||
ent->mData = new T(mozilla::Forward<Args>(aConstructionArgs)...);
|
||||
}
|
||||
return ent->mData;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user