import from UXP: Issue #1375 - Part 1: Allow moving a reference into nsInterfaceHashtable (53e2e5d8)

This commit is contained in:
2023-03-02 15:01:22 +08:00
parent e1c57cc7b6
commit 2e24a51c9c
+30
View File
@@ -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__