mirror of
https://repo.dactyloidae.xyz/Dactyloidae/UXP.git
synced 2026-09-29 20:07:30 +09:00
Issue #1375 - Part 1: Allow moving a reference into nsInterfaceHashtable
This commit is contained in:
parent
2d7d00b75a
commit
53e2e5d8d6
1 changed files with 30 additions and 0 deletions
|
|
@ -52,6 +52,21 @@ public:
|
||||||
* @return The entry, or nullptr if not found. Do not release this pointer!
|
* @return The entry, or nullptr if not found. Do not release this pointer!
|
||||||
*/
|
*/
|
||||||
Interface* GetWeak(KeyType aKey, bool* aFound = nullptr) const;
|
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>
|
template<typename K, typename T>
|
||||||
|
|
@ -138,4 +153,19 @@ nsInterfaceHashtable<KeyClass, Interface>::GetWeak(KeyType aKey,
|
||||||
return nullptr;
|
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__
|
#endif // nsInterfaceHashtable_h__
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue