mirror of
https://github.com/roytam1/basilisk55.git
synced 2026-05-26 15:02:46 +00:00
import from UXP: Issue #1375 - Part 1: Allow moving a reference into nsInterfaceHashtable (53e2e5d8)
This commit is contained in:
@@ -53,6 +53,21 @@ public:
|
||||
* @return The entry, or nullptr if not found. Do not release this pointer!
|
||||
*/
|
||||
Interface* GetWeak(KeyType aKey, bool* aFound = nullptr) const;
|
||||
|
||||
/**
|
||||
* Allows inserting a value into the hashtable, moving its owning reference
|
||||
* count into the hashtable, avoiding an AddRef.
|
||||
*/
|
||||
void Put(KeyType aKey, already_AddRefed<Interface>&& aData)
|
||||
{
|
||||
if (!Put(aKey, mozilla::Move(aData), mozilla::fallible)) {
|
||||
NS_ABORT_OOM(this->mTable.EntrySize() * this->mTable.EntryCount());
|
||||
}
|
||||
}
|
||||
|
||||
MOZ_MUST_USE bool Put(KeyType aKey, already_AddRefed<Interface>&& aData,
|
||||
const mozilla::fallible_t&);
|
||||
using base_type::Put;
|
||||
};
|
||||
|
||||
template<typename K, typename T>
|
||||
@@ -139,4 +154,19 @@ nsInterfaceHashtable<KeyClass, Interface>::GetWeak(KeyType aKey,
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
template<class KeyClass, class Interface>
|
||||
bool
|
||||
nsInterfaceHashtable<KeyClass, Interface>::Put(KeyType aKey,
|
||||
already_AddRefed<Interface>&& aValue,
|
||||
const mozilla::fallible_t&)
|
||||
{
|
||||
typename base_type::EntryType* ent = this->PutEntry(aKey);
|
||||
if (!ent) {
|
||||
return false;
|
||||
}
|
||||
|
||||
ent->mData = aValue;
|
||||
return true;
|
||||
}
|
||||
|
||||
#endif // nsInterfaceHashtable_h__
|
||||
|
||||
Reference in New Issue
Block a user