mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-26 22:32:46 +00:00
Bug 1688833 - Migrate LookupForAdd to WithEntryHandle in modules/libpref. r=KrisWright
Differential Revision: https://phabricator.services.mozilla.com/D104196
This commit is contained in:
parent
8528e2fa1d
commit
5a4b6bc937
@ -2607,21 +2607,21 @@ nsPrefBranch::AddObserverImpl(const nsACString& aDomain, nsIObserver* aObserver,
|
||||
pCallback = new PrefCallback(prefName, aObserver, this);
|
||||
}
|
||||
|
||||
auto p = mObservers.LookupForAdd(pCallback);
|
||||
if (p) {
|
||||
NS_WARNING("Ignoring duplicate observer.");
|
||||
delete pCallback;
|
||||
return NS_OK;
|
||||
}
|
||||
mObservers.WithEntryHandle(pCallback, [&](auto&& p) {
|
||||
if (p) {
|
||||
NS_WARNING("Ignoring duplicate observer.");
|
||||
delete pCallback;
|
||||
} else {
|
||||
p.Insert(pCallback);
|
||||
|
||||
p.OrInsert([&pCallback]() { return pCallback; });
|
||||
|
||||
// We must pass a fully qualified preference name to the callback
|
||||
// aDomain == nullptr is the only possible failure, and we trapped it with
|
||||
// NS_ENSURE_ARG above.
|
||||
Preferences::RegisterCallback(NotifyObserver, prefName, pCallback,
|
||||
Preferences::PrefixMatch,
|
||||
/* isPriority */ false);
|
||||
// We must pass a fully qualified preference name to the callback
|
||||
// aDomain == nullptr is the only possible failure, and we trapped it with
|
||||
// NS_ENSURE_ARG above.
|
||||
Preferences::RegisterCallback(NotifyObserver, prefName, pCallback,
|
||||
Preferences::PrefixMatch,
|
||||
/* isPriority */ false);
|
||||
}
|
||||
});
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
@ -638,11 +638,11 @@ class MOZ_RAII SharedPrefMapBuilder {
|
||||
ValueIdx Add(const ValueType& aDefaultValue) {
|
||||
auto index = uint16_t(mDefaultEntries.Count());
|
||||
|
||||
auto entry = mDefaultEntries.LookupForAdd(aDefaultValue).OrInsert([&]() {
|
||||
return Entry{index, false, aDefaultValue};
|
||||
});
|
||||
return mDefaultEntries.WithEntryHandle(aDefaultValue, [&](auto&& entry) {
|
||||
entry.OrInsertWith([&] { return Entry{index, false, aDefaultValue}; });
|
||||
|
||||
return {entry.mIndex, false};
|
||||
return ValueIdx{entry.Data().mIndex, false};
|
||||
});
|
||||
}
|
||||
|
||||
// Adds an entry for a preference with a user value to the array. Regardless
|
||||
|
Loading…
Reference in New Issue
Block a user