Bug 1547351 - add IsEmpty and fix OrInsert signature for nsBaseHashtable. r=Ehsan

Differential Revision: https://phabricator.services.mozilla.com/D38597

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Alexis Beingessner 2019-07-24 14:10:56 +00:00
parent c6d6d1dfde
commit 57498bb3b4
2 changed files with 9 additions and 3 deletions

View File

@ -203,7 +203,7 @@ void nsFrameMessageManager::AddMessageListener(const nsAString& aMessageName,
MessageListener& aListener,
bool aListenWhenClosed,
ErrorResult& aError) {
auto listeners = mListeners.LookupForAdd(aMessageName).OrInsert([]() {
auto& listeners = mListeners.LookupForAdd(aMessageName).OrInsert([]() {
return new nsAutoTObserverArray<nsMessageListenerInfo, 1>();
});
uint32_t len = listeners->Length();
@ -272,7 +272,7 @@ void nsFrameMessageManager::AddWeakMessageListener(
}
#endif
auto listeners = mListeners.LookupForAdd(aMessageName).OrInsert([]() {
auto& listeners = mListeners.LookupForAdd(aMessageName).OrInsert([]() {
return new nsAutoTObserverArray<nsMessageListenerInfo, 1>();
});
uint32_t len = listeners->Length();

View File

@ -71,6 +71,12 @@ class nsBaseHashtable
*/
uint32_t Count() const { return nsTHashtable<EntryType>::Count(); }
/**
* Return whether the table is empty.
* @return whether empty
*/
bool IsEmpty() const { return nsTHashtable<EntryType>::IsEmpty(); }
/**
* retrieve the value for a key.
* @param aKey the key to retreive
@ -286,7 +292,7 @@ class nsBaseHashtable
}
template <class F>
UserDataType OrInsert(F func) {
DataType& OrInsert(F func) {
MOZ_ASSERT(mTableGeneration == mTable.GetGeneration());
MOZ_ASSERT(mEntry);
if (!mExistingEntry) {