зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1691894 - Simplify uses of WithEntryHandle that only use OrInsert(With) by using GetOrInsertWith. r=xpcom-reviewers,necko-reviewers,jgilbert,nika
Differential Revision: https://phabricator.services.mozilla.com/D104676
This commit is contained in:
Родитель
bde1e69284
Коммит
d2caea36fa
|
@ -34,11 +34,9 @@ already_AddRefed<BrowsingContextGroup> BrowsingContextGroup::GetOrCreate(
|
|||
ClearOnShutdown(&sBrowsingContextGroups);
|
||||
}
|
||||
|
||||
return sBrowsingContextGroups->WithEntryHandle(aId, [&aId](auto&& entry) {
|
||||
RefPtr<BrowsingContextGroup> group = entry.OrInsertWith(
|
||||
[&aId] { return do_AddRef(new BrowsingContextGroup(aId)); });
|
||||
return group.forget();
|
||||
});
|
||||
RefPtr<BrowsingContextGroup> group = sBrowsingContextGroups->GetOrInsertWith(
|
||||
aId, [&aId] { return do_AddRef(new BrowsingContextGroup(aId)); });
|
||||
return group.forget();
|
||||
}
|
||||
|
||||
already_AddRefed<BrowsingContextGroup> BrowsingContextGroup::Create() {
|
||||
|
|
|
@ -240,23 +240,14 @@ void EffectCompositor::RequestRestyle(dom::Element* aElement,
|
|||
auto& elementsToRestyle = mElementsToRestyle[aCascadeLevel];
|
||||
PseudoElementHashEntry::KeyType key = {aElement, aPseudoType};
|
||||
|
||||
bool& restyleEntry = elementsToRestyle.GetOrInsert(key, false);
|
||||
if (aRestyleType == RestyleType::Throttled) {
|
||||
elementsToRestyle.WithEntryHandle(
|
||||
key, [](auto&& entry) { entry.OrInsert(false); });
|
||||
mPresContext->PresShell()->SetNeedThrottledAnimationFlush();
|
||||
} else {
|
||||
// Update hashtable first in case PostRestyleForAnimation mutates it.
|
||||
// Update hashtable first in case PostRestyleForAnimation mutates it
|
||||
// and invalidates the restyleEntry reference.
|
||||
// (It shouldn't, but just to be sure.)
|
||||
const bool skipRestyle =
|
||||
elementsToRestyle.WithEntryHandle(key, [](auto&& p) {
|
||||
if (p) {
|
||||
return std::exchange(p.Data(), true);
|
||||
}
|
||||
|
||||
p.Insert(true);
|
||||
return false;
|
||||
});
|
||||
|
||||
bool skipRestyle = std::exchange(restyleEntry, true);
|
||||
if (!skipRestyle) {
|
||||
PostRestyleForAnimation(aElement, aPseudoType, aCascadeLevel);
|
||||
}
|
||||
|
|
|
@ -1105,12 +1105,8 @@ already_AddRefed<Promise> CustomElementRegistry::WhenDefined(
|
|||
return promise.forget();
|
||||
}
|
||||
|
||||
return mWhenDefinedPromiseMap
|
||||
.WithEntryHandle(nameAtom,
|
||||
[&promise](auto&& entry) -> RefPtr<Promise> {
|
||||
return entry.OrInsert(std::move(promise));
|
||||
})
|
||||
.forget();
|
||||
return do_AddRef(
|
||||
mWhenDefinedPromiseMap.GetOrInsert(nameAtom, std::move(promise)));
|
||||
}
|
||||
|
||||
namespace {
|
||||
|
|
|
@ -1637,9 +1637,7 @@ class Document : public nsINode,
|
|||
RawServoSelectorList* GetListOrInsertFrom(const nsACString& aSelector,
|
||||
F&& aFrom) {
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
return mTable.WithEntryHandle(aSelector, [&aFrom](auto&& entry) {
|
||||
return entry.OrInsertWith(std::forward<F>(aFrom)).get();
|
||||
});
|
||||
return mTable.GetOrInsertWith(aSelector, std::forward<F>(aFrom)).get();
|
||||
}
|
||||
|
||||
~SelectorCache();
|
||||
|
|
|
@ -218,11 +218,8 @@ void DocumentOrShadowRoot::CloneAdoptedSheetsFrom(
|
|||
MOZ_ASSERT(clonedSheetMap);
|
||||
|
||||
for (const StyleSheet* sheet : aSource.mAdoptedStyleSheets) {
|
||||
RefPtr<StyleSheet> clone = clonedSheetMap->WithEntryHandle(
|
||||
sheet, [&sheet, &ownerDoc](auto&& entry) {
|
||||
return entry.OrInsertWith(
|
||||
[&] { return sheet->CloneAdoptedSheet(ownerDoc); });
|
||||
});
|
||||
RefPtr<StyleSheet> clone = clonedSheetMap->GetOrInsertWith(
|
||||
sheet, [&] { return sheet->CloneAdoptedSheet(ownerDoc); });
|
||||
MOZ_ASSERT(clone);
|
||||
MOZ_DIAGNOSTIC_ASSERT(clone->ConstructorDocumentMatches(ownerDoc));
|
||||
DebugOnly<bool> succeeded = list.AppendElement(std::move(clone), fallible);
|
||||
|
@ -755,10 +752,9 @@ nsRadioGroupStruct* DocumentOrShadowRoot::GetRadioGroup(
|
|||
|
||||
nsRadioGroupStruct* DocumentOrShadowRoot::GetOrCreateRadioGroup(
|
||||
const nsAString& aName) {
|
||||
return mRadioGroups.WithEntryHandle(aName, [](auto&& entry) {
|
||||
return entry.OrInsertWith([] { return MakeUnique<nsRadioGroupStruct>(); })
|
||||
.get();
|
||||
});
|
||||
return mRadioGroups
|
||||
.GetOrInsertWith(aName, [] { return MakeUnique<nsRadioGroupStruct>(); })
|
||||
.get();
|
||||
}
|
||||
|
||||
int32_t DocumentOrShadowRoot::StyleOrderIndexOfSheet(
|
||||
|
|
|
@ -3954,14 +3954,12 @@ void Element::RegisterIntersectionObserver(DOMIntersectionObserver* aObserver) {
|
|||
return;
|
||||
}
|
||||
|
||||
observers->WithEntryHandle(aObserver, [](auto&& entry) {
|
||||
// Value can be:
|
||||
// -2: Makes sure next calculated threshold always differs, leading to a
|
||||
// notification task being scheduled.
|
||||
// -1: Non-intersecting.
|
||||
// >= 0: Intersecting, valid index of aObserver->mThresholds.
|
||||
entry.OrInsert(eUninitialized);
|
||||
});
|
||||
// Value can be:
|
||||
// -2: Makes sure next calculated threshold always differs, leading to a
|
||||
// notification task being scheduled.
|
||||
// -1: Non-intersecting.
|
||||
// >= 0: Intersecting, valid index of aObserver->mThresholds.
|
||||
Unused << observers->GetOrInsert(aObserver, eUninitialized);
|
||||
}
|
||||
|
||||
void Element::UnregisterIntersectionObserver(
|
||||
|
|
|
@ -150,10 +150,7 @@ void ResizeObserver::Observe(Element& aTarget,
|
|||
mDocument->AddResizeObserver(*this);
|
||||
}
|
||||
|
||||
auto& observation = mObservationMap.WithEntryHandle(
|
||||
&aTarget, [](auto&& entry) -> RefPtr<ResizeObservation>& {
|
||||
return entry.OrInsert(nullptr);
|
||||
});
|
||||
auto& observation = mObservationMap.GetOrInsert(&aTarget);
|
||||
if (observation) {
|
||||
if (observation->BoxOptions() == aOptions.mBox) {
|
||||
// Already observed this target and the observed box is the same, so
|
||||
|
|
|
@ -320,15 +320,15 @@ void nsMutationReceiver::ContentRemoved(nsIContent* aChild,
|
|||
bool transientExists = false;
|
||||
bool isNewEntry = false;
|
||||
auto* const transientReceivers =
|
||||
Observer()->mTransientReceivers.WithEntryHandle(
|
||||
aChild, [&isNewEntry](auto&& entry) {
|
||||
return entry
|
||||
.OrInsertWith([&isNewEntry] {
|
||||
isNewEntry = true;
|
||||
return MakeUnique<nsCOMArray<nsMutationReceiver>>();
|
||||
})
|
||||
.get();
|
||||
});
|
||||
Observer()
|
||||
->mTransientReceivers
|
||||
.GetOrInsertWith(
|
||||
aChild,
|
||||
[&isNewEntry] {
|
||||
isNewEntry = true;
|
||||
return MakeUnique<nsCOMArray<nsMutationReceiver>>();
|
||||
})
|
||||
.get();
|
||||
if (!isNewEntry) {
|
||||
for (int32_t i = 0; i < transientReceivers->Count(); ++i) {
|
||||
nsMutationReceiver* r = transientReceivers->ObjectAt(i);
|
||||
|
@ -1039,13 +1039,11 @@ void nsAutoMutationBatch::Done() {
|
|||
|
||||
if (allObservers.Length()) {
|
||||
auto* const transientReceivers =
|
||||
ob->mTransientReceivers.WithEntryHandle(removed, [](auto&& entry) {
|
||||
return entry
|
||||
.OrInsertWith([] {
|
||||
return MakeUnique<nsCOMArray<nsMutationReceiver>>();
|
||||
})
|
||||
.get();
|
||||
});
|
||||
ob->mTransientReceivers
|
||||
.GetOrInsertWith(
|
||||
removed,
|
||||
[] { return MakeUnique<nsCOMArray<nsMutationReceiver>>(); })
|
||||
.get();
|
||||
for (uint32_t k = 0; k < allObservers.Length(); ++k) {
|
||||
nsMutationReceiver* r = allObservers[k];
|
||||
nsMutationReceiver* orig = r->GetParent() ? r->GetParent() : r;
|
||||
|
|
|
@ -240,14 +240,14 @@ void nsFrameMessageManager::AddMessageListener(const nsAString& aMessageName,
|
|||
bool aListenWhenClosed,
|
||||
ErrorResult& aError) {
|
||||
auto* const listeners =
|
||||
mListeners.WithEntryHandle(aMessageName, [](auto&& entry) {
|
||||
return entry
|
||||
.OrInsertWith([] {
|
||||
return MakeUnique<
|
||||
nsAutoTObserverArray<nsMessageListenerInfo, 1>>();
|
||||
})
|
||||
.get();
|
||||
});
|
||||
mListeners
|
||||
.GetOrInsertWith(
|
||||
aMessageName,
|
||||
[] {
|
||||
return MakeUnique<
|
||||
nsAutoTObserverArray<nsMessageListenerInfo, 1>>();
|
||||
})
|
||||
.get();
|
||||
uint32_t len = listeners->Length();
|
||||
for (uint32_t i = 0; i < len; ++i) {
|
||||
MessageListener* strongListener = listeners->ElementAt(i).mStrongListener;
|
||||
|
@ -315,14 +315,14 @@ void nsFrameMessageManager::AddWeakMessageListener(
|
|||
#endif
|
||||
|
||||
auto* const listeners =
|
||||
mListeners.WithEntryHandle(aMessageName, [](auto&& entry) {
|
||||
return entry
|
||||
.OrInsertWith([] {
|
||||
return MakeUnique<
|
||||
nsAutoTObserverArray<nsMessageListenerInfo, 1>>();
|
||||
})
|
||||
.get();
|
||||
});
|
||||
mListeners
|
||||
.GetOrInsertWith(
|
||||
aMessageName,
|
||||
[] {
|
||||
return MakeUnique<
|
||||
nsAutoTObserverArray<nsMessageListenerInfo, 1>>();
|
||||
})
|
||||
.get();
|
||||
uint32_t len = listeners->Length();
|
||||
for (uint32_t i = 0; i < len; ++i) {
|
||||
if (listeners->ElementAt(i).mWeakListener == weak) {
|
||||
|
|
|
@ -7160,13 +7160,13 @@ ChromeMessageBroadcaster* nsGlobalWindowInner::GetGroupMessageManager(
|
|||
const nsAString& aGroup) {
|
||||
MOZ_ASSERT(IsChromeWindow());
|
||||
|
||||
return mChromeFields.mGroupMessageManagers.WithEntryHandle(
|
||||
aGroup, [&](auto&& entry) {
|
||||
return entry
|
||||
.OrInsertWith(
|
||||
[&] { return new ChromeMessageBroadcaster(MessageManager()); })
|
||||
.get();
|
||||
});
|
||||
return mChromeFields.mGroupMessageManagers
|
||||
.GetOrInsertWith(
|
||||
aGroup,
|
||||
[&] {
|
||||
return MakeAndAddRef<ChromeMessageBroadcaster>(MessageManager());
|
||||
})
|
||||
.get();
|
||||
}
|
||||
|
||||
void nsGlobalWindowInner::InitWasOffline() { mWasOffline = NS_IsOffline(); }
|
||||
|
|
|
@ -82,12 +82,11 @@ void BroadcastChannelService::RegisterActor(
|
|||
MOZ_ASSERT(aParent);
|
||||
|
||||
auto* const parents =
|
||||
mAgents.WithEntryHandle(aOriginChannelKey, [](auto&& entry) {
|
||||
return entry
|
||||
.OrInsertWith(
|
||||
[] { return MakeUnique<nsTArray<BroadcastChannelParent*>>(); })
|
||||
.get();
|
||||
});
|
||||
mAgents
|
||||
.GetOrInsertWith(
|
||||
aOriginChannelKey,
|
||||
[] { return MakeUnique<nsTArray<BroadcastChannelParent*>>(); })
|
||||
.get();
|
||||
|
||||
MOZ_ASSERT(!parents->Contains(aParent));
|
||||
parents->AppendElement(aParent);
|
||||
|
|
|
@ -81,11 +81,10 @@ nsCommandManager::AddCommandObserver(nsIObserver* aCommandObserver,
|
|||
|
||||
// for each command in the table, we make a list of observers for that command
|
||||
auto* const commandObservers =
|
||||
mObserversTable.WithEntryHandle(aCommandToObserve, [](auto&& entry) {
|
||||
return entry
|
||||
.OrInsertWith([] { return mozilla::MakeUnique<ObserverList>(); })
|
||||
.get();
|
||||
});
|
||||
mObserversTable
|
||||
.GetOrInsertWith(aCommandToObserve,
|
||||
[] { return mozilla::MakeUnique<ObserverList>(); })
|
||||
.get();
|
||||
|
||||
// need to check that this command observer hasn't already been registered
|
||||
int32_t existingIndex = commandObservers->IndexOf(aCommandObserver);
|
||||
|
|
|
@ -374,12 +374,10 @@ void EventListenerService::NotifyAboutMainThreadListenerChangeInternal(
|
|||
}
|
||||
|
||||
RefPtr<EventListenerChange> changes =
|
||||
mPendingListenerChangesSet.WithEntryHandle(aTarget, [&](auto&& entry) {
|
||||
return entry.OrInsertWith([&] {
|
||||
EventListenerChange* c = new EventListenerChange(aTarget);
|
||||
mPendingListenerChanges->AppendElement(c);
|
||||
return c;
|
||||
});
|
||||
mPendingListenerChangesSet.GetOrInsertWith(aTarget, [&] {
|
||||
auto c = MakeRefPtr<EventListenerChange>(aTarget);
|
||||
mPendingListenerChanges->AppendElement(c);
|
||||
return c;
|
||||
});
|
||||
changes->AddChangedListenerName(aName);
|
||||
}
|
||||
|
|
|
@ -4696,11 +4696,10 @@ OverOutElementsWrapper* EventStateManager::GetWrapperByEventID(
|
|||
}
|
||||
return mMouseEnterLeaveHelper;
|
||||
}
|
||||
return mPointersEnterLeaveHelper.WithEntryHandle(
|
||||
pointer->pointerId, [](auto&& entry) {
|
||||
return entry.OrInsertWith([] { return new OverOutElementsWrapper(); })
|
||||
.get();
|
||||
});
|
||||
return mPointersEnterLeaveHelper
|
||||
.GetOrInsertWith(pointer->pointerId,
|
||||
[] { return new OverOutElementsWrapper(); })
|
||||
.get();
|
||||
}
|
||||
|
||||
/* static */
|
||||
|
|
|
@ -104,15 +104,14 @@ static bool DocAllResultMatch(Element* aElement, int32_t aNamespaceID,
|
|||
}
|
||||
|
||||
nsContentList* HTMLAllCollection::GetDocumentAllList(const nsAString& aID) {
|
||||
return mNamedMap.WithEntryHandle(aID, [&](auto&& entry) {
|
||||
return entry
|
||||
.OrInsertWith([this, &aID] {
|
||||
RefPtr<nsAtom> id = NS_Atomize(aID);
|
||||
return new nsContentList(mDocument, DocAllResultMatch, nullptr,
|
||||
nullptr, true, id);
|
||||
})
|
||||
.get();
|
||||
});
|
||||
return mNamedMap
|
||||
.GetOrInsertWith(aID,
|
||||
[this, &aID] {
|
||||
RefPtr<nsAtom> id = NS_Atomize(aID);
|
||||
return new nsContentList(mDocument, DocAllResultMatch,
|
||||
nullptr, nullptr, true, id);
|
||||
})
|
||||
.get();
|
||||
}
|
||||
|
||||
void HTMLAllCollection::NamedGetter(
|
||||
|
|
|
@ -2170,10 +2170,8 @@ HTMLFormElement::WalkRadioGroup(const nsAString& aName,
|
|||
void HTMLFormElement::AddToRadioGroup(const nsAString& aName,
|
||||
HTMLInputElement* aRadio) {
|
||||
if (aRadio->IsRequired()) {
|
||||
mRequiredRadioButtonCounts.WithEntryHandle(aName, [](auto&& entry) {
|
||||
uint32_t& value = entry.OrInsert(0);
|
||||
++value;
|
||||
});
|
||||
uint32_t& value = mRequiredRadioButtonCounts.GetOrInsert(aName, 0);
|
||||
++value;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -5451,8 +5451,7 @@ void Snapshot::SaveItem(const nsAString& aKey, const LSValue& aOldValue,
|
|||
}
|
||||
|
||||
if (!mLoadedItems.GetEntry(aKey) && !mUnknownItems.GetEntry(aKey)) {
|
||||
mValues.WithEntryHandle(aKey,
|
||||
[&](auto&& entry) { entry.OrInsert(aOldValue); });
|
||||
Unused << mValues.GetOrInsert(aKey, aOldValue);
|
||||
}
|
||||
|
||||
if (aAffectsOrder && !mSavedKeys) {
|
||||
|
|
|
@ -1712,14 +1712,13 @@ bool SkeletonState::DecodeFisbone(ogg_packet* aPacket) {
|
|||
|
||||
if ((i == 0 && IsAscii(strMsg)) || (i != 0 && IsUtf8(strMsg))) {
|
||||
EMsgHeaderType eHeaderType = kFieldTypeMaps[i].mMsgHeaderType;
|
||||
field->mValuesStore.WithEntryHandle(eHeaderType, [=](auto&& entry) {
|
||||
entry.OrInsertWith([i, msgHead, msgProbe]() {
|
||||
uint32_t nameLen =
|
||||
strlen(kFieldTypeMaps[i].mPatternToRecognize);
|
||||
return MakeUnique<nsCString>(msgHead + nameLen,
|
||||
msgProbe - msgHead - nameLen);
|
||||
});
|
||||
});
|
||||
Unused << field->mValuesStore.GetOrInsertWith(
|
||||
eHeaderType, [i, msgHead, msgProbe]() {
|
||||
uint32_t nameLen =
|
||||
strlen(kFieldTypeMaps[i].mPatternToRecognize);
|
||||
return MakeUnique<nsCString>(msgHead + nameLen,
|
||||
msgProbe - msgHead - nameLen);
|
||||
});
|
||||
isContentTypeParsed = i == 0 ? true : isContentTypeParsed;
|
||||
}
|
||||
break;
|
||||
|
|
|
@ -380,8 +380,7 @@ nsresult PaymentRequestManager::SendRequestPayment(
|
|||
}
|
||||
|
||||
if (aResponseExpected) {
|
||||
mActivePayments.WithEntryHandle(aRequest,
|
||||
[](auto&& count) { ++count.OrInsert(0); });
|
||||
++mActivePayments.GetOrInsert(aRequest, 0);
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
|
|
@ -4368,15 +4368,12 @@ already_AddRefed<QuotaObject> QuotaManager::GetQuotaObject(
|
|||
// pointer directly since QuotaObject::AddRef would try to acquire the same
|
||||
// mutex.
|
||||
const NotNull<QuotaObject*> quotaObject =
|
||||
originInfo->mQuotaObjects.WithEntryHandle(
|
||||
path, [&](auto&& entryHandle) {
|
||||
return entryHandle.OrInsertWith([&] {
|
||||
// Create a new QuotaObject. The hashtable is not responsible to
|
||||
// delete the QuotaObject.
|
||||
return WrapNotNullUnchecked(
|
||||
new QuotaObject(originInfo, aClientType, path, fileSize));
|
||||
});
|
||||
});
|
||||
originInfo->mQuotaObjects.GetOrInsertWith(path, [&] {
|
||||
// Create a new QuotaObject. The hashtable is not responsible to
|
||||
// delete the QuotaObject.
|
||||
return WrapNotNullUnchecked(
|
||||
new QuotaObject(originInfo, aClientType, path, fileSize));
|
||||
});
|
||||
|
||||
// Addref the QuotaObject and move the ownership to the result. This must
|
||||
// happen before we unlock!
|
||||
|
@ -6941,21 +6938,16 @@ auto QuotaManager::GetDirectoryLockTable(PersistenceType aPersistenceType)
|
|||
bool QuotaManager::IsSanitizedOriginValid(const nsACString& aSanitizedOrigin) {
|
||||
AssertIsOnIOThread();
|
||||
|
||||
return mValidOrigins.WithEntryHandle(
|
||||
aSanitizedOrigin, [&aSanitizedOrigin](auto&& entry) {
|
||||
if (entry) {
|
||||
// We already parsed this sanitized origin string.
|
||||
return entry.Data();
|
||||
}
|
||||
// Do not parse this sanitized origin string, if we already parsed it.
|
||||
return mValidOrigins.GetOrInsertWith(aSanitizedOrigin, [&aSanitizedOrigin] {
|
||||
nsCString spec;
|
||||
OriginAttributes attrs;
|
||||
nsCString originalSuffix;
|
||||
const auto result = OriginParser::ParseOrigin(aSanitizedOrigin, spec,
|
||||
&attrs, originalSuffix);
|
||||
|
||||
nsCString spec;
|
||||
OriginAttributes attrs;
|
||||
nsCString originalSuffix;
|
||||
const auto result = OriginParser::ParseOrigin(aSanitizedOrigin, spec,
|
||||
&attrs, originalSuffix);
|
||||
|
||||
return entry.Insert(result == OriginParser::ValidOrigin);
|
||||
});
|
||||
return result == OriginParser::ValidOrigin;
|
||||
});
|
||||
}
|
||||
|
||||
int64_t QuotaManager::GenerateDirectoryLockId() {
|
||||
|
|
|
@ -1594,13 +1594,9 @@ ServiceWorkerManager::GetOrCreateJobQueue(const nsACString& aKey,
|
|||
.get();
|
||||
}
|
||||
|
||||
return data->mJobQueues
|
||||
.WithEntryHandle(aScope,
|
||||
[](auto&& entry) {
|
||||
return entry.OrInsertWith(
|
||||
[] { return new ServiceWorkerJobQueue(); });
|
||||
})
|
||||
.forget();
|
||||
RefPtr queue = data->mJobQueues.GetOrInsertWith(
|
||||
aScope, [] { return new ServiceWorkerJobQueue(); });
|
||||
return queue.forget();
|
||||
}
|
||||
|
||||
/* static */
|
||||
|
@ -1911,12 +1907,11 @@ void ServiceWorkerManager::AddScopeAndRegistration(
|
|||
MOZ_ASSERT(!scopeKey.IsEmpty());
|
||||
|
||||
auto* const data =
|
||||
swm->mRegistrationInfos.WithEntryHandle(scopeKey, [](auto&& entry) {
|
||||
return entry
|
||||
.OrInsertWith(
|
||||
[] { return MakeUnique<RegistrationDataPerPrincipal>(); })
|
||||
.get();
|
||||
});
|
||||
swm->mRegistrationInfos
|
||||
.GetOrInsertWith(
|
||||
scopeKey,
|
||||
[] { return MakeUnique<RegistrationDataPerPrincipal>(); })
|
||||
.get();
|
||||
|
||||
data->mScopeContainer.InsertScope(aScope);
|
||||
data->mInfos.Put(aScope, RefPtr{aInfo});
|
||||
|
|
|
@ -632,11 +632,10 @@ BackgroundSessionStorageManager* BackgroundSessionStorageManager::GetOrCreate(
|
|||
}));
|
||||
}
|
||||
|
||||
return sManagers->WithEntryHandle(aTopContextId, [](auto&& entry) {
|
||||
return entry
|
||||
.OrInsertWith([] { return new BackgroundSessionStorageManager(); })
|
||||
.get();
|
||||
});
|
||||
return sManagers
|
||||
->GetOrInsertWith(aTopContextId,
|
||||
[] { return new BackgroundSessionStorageManager(); })
|
||||
.get();
|
||||
}
|
||||
|
||||
BackgroundSessionStorageManager::BackgroundSessionStorageManager() {
|
||||
|
|
|
@ -1150,18 +1150,18 @@ bool RuntimeService::RegisterWorker(WorkerPrivate& aWorkerPrivate) {
|
|||
MutexAutoLock lock(mMutex);
|
||||
|
||||
auto* const domainInfo =
|
||||
mDomainMap.WithEntryHandle(domain, [&](auto&& entry) {
|
||||
return entry
|
||||
.OrInsertWith([&domain, parent] {
|
||||
NS_ASSERTION(!parent, "Shouldn't have a parent here!");
|
||||
Unused << parent; // silence clang -Wunused-lambda-capture in
|
||||
// opt builds
|
||||
auto wdi = MakeUnique<WorkerDomainInfo>();
|
||||
wdi->mDomain = domain;
|
||||
return wdi;
|
||||
})
|
||||
.get();
|
||||
});
|
||||
mDomainMap
|
||||
.GetOrInsertWith(
|
||||
domain,
|
||||
[&domain, parent] {
|
||||
NS_ASSERTION(!parent, "Shouldn't have a parent here!");
|
||||
Unused << parent; // silence clang -Wunused-lambda-capture in
|
||||
// opt builds
|
||||
auto wdi = MakeUnique<WorkerDomainInfo>();
|
||||
wdi->mDomain = domain;
|
||||
return wdi;
|
||||
})
|
||||
.get();
|
||||
|
||||
queued = gMaxWorkersPerDomain &&
|
||||
domainInfo->ActiveWorkerCount() >= gMaxWorkersPerDomain &&
|
||||
|
@ -1222,14 +1222,12 @@ bool RuntimeService::RegisterWorker(WorkerPrivate& aWorkerPrivate) {
|
|||
if (!isServiceWorker) {
|
||||
// Service workers are excluded since their lifetime is separate from
|
||||
// that of dom windows.
|
||||
if (auto* const windowArray = mWindowMap.WithEntryHandle(
|
||||
window,
|
||||
[](auto&& entry) {
|
||||
return entry
|
||||
.OrInsertWith(
|
||||
[] { return MakeUnique<nsTArray<WorkerPrivate*>>(1); })
|
||||
.get();
|
||||
});
|
||||
if (auto* const windowArray =
|
||||
mWindowMap
|
||||
.GetOrInsertWith(
|
||||
window,
|
||||
[] { return MakeUnique<nsTArray<WorkerPrivate*>>(1); })
|
||||
.get();
|
||||
!windowArray->Contains(&aWorkerPrivate)) {
|
||||
windowArray->AppendElement(&aWorkerPrivate);
|
||||
} else {
|
||||
|
|
|
@ -867,11 +867,9 @@ EGLSurface GLContextEGL::CreateWaylandBufferSurface(
|
|||
config, reinterpret_cast<EGLNativeWindowType>(eglwindow), 0);
|
||||
if (surface) {
|
||||
#ifdef MOZ_GTK_WAYLAND
|
||||
WaylandGLSurface* waylandData = new WaylandGLSurface(wlsurface, eglwindow);
|
||||
// XXX This looks as if this should unconditionally insert. Otherwise,
|
||||
// waylandData would be leaked.
|
||||
sWaylandGLSurface.WithEntryHandle(
|
||||
surface, [&](auto&& entry) { entry.OrInsert(waylandData); });
|
||||
MOZ_ASSERT(!sWaylandGLSurface.Contains(surface));
|
||||
sWaylandGLSurface.GetOrInsert(surface,
|
||||
new WaylandGLSurface(wlsurface, eglwindow));
|
||||
#endif
|
||||
}
|
||||
|
||||
|
|
|
@ -1591,17 +1591,22 @@ void gfxFcPlatformFontList::InitSharedFontListForPlatform() {
|
|||
aFamilyName = ToCharPtr(canonical);
|
||||
|
||||
// Add new family record if one doesn't already exist.
|
||||
faceListPtr = faces.WithEntryHandle(keyName, [&](auto&& faceList) {
|
||||
if (!faceList) {
|
||||
faceList.Insert(MakeUnique<FaceInitArray>());
|
||||
FontVisibility visibility =
|
||||
aAppFont ? FontVisibility::Base : GetVisibilityForFamily(keyName);
|
||||
families.AppendElement(fontlist::Family::InitData(
|
||||
keyName, aFamilyName, fontlist::Family::kNoIndex, visibility,
|
||||
/*bundled*/ aAppFont, /*badUnderline*/ false));
|
||||
}
|
||||
return faceList.Data().get();
|
||||
});
|
||||
faceListPtr =
|
||||
faces
|
||||
.GetOrInsertWith(
|
||||
keyName,
|
||||
[&] {
|
||||
FontVisibility visibility =
|
||||
aAppFont ? FontVisibility::Base
|
||||
: GetVisibilityForFamily(keyName);
|
||||
families.AppendElement(fontlist::Family::InitData(
|
||||
keyName, aFamilyName, fontlist::Family::kNoIndex,
|
||||
visibility,
|
||||
/*bundled*/ aAppFont, /*badUnderline*/ false));
|
||||
|
||||
return MakeUnique<FaceInitArray>();
|
||||
})
|
||||
.get();
|
||||
}
|
||||
|
||||
char* s = (char*)FcNameUnparse(aPattern);
|
||||
|
@ -1650,18 +1655,21 @@ void gfxFcPlatformFontList::InitSharedFontListForPlatform() {
|
|||
keyName = otherFamilyName;
|
||||
ToLowerCase(keyName);
|
||||
|
||||
faces.WithEntryHandle(keyName, [&](auto&& faceList) {
|
||||
if (!faceList) {
|
||||
faceList.Insert(MakeUnique<FaceInitArray>());
|
||||
FontVisibility visibility =
|
||||
aAppFont ? FontVisibility::Base : GetVisibilityForFamily(keyName);
|
||||
families.AppendElement(fontlist::Family::InitData(
|
||||
keyName, otherFamilyName, fontlist::Family::kNoIndex, visibility,
|
||||
/*bundled*/ aAppFont, /*badUnderline*/ false));
|
||||
}
|
||||
faceList.Data()->AppendElement(fontlist::Face::InitData{
|
||||
descriptor, 0, false, weight, stretch, style});
|
||||
});
|
||||
faces
|
||||
.GetOrInsertWith(keyName,
|
||||
[&] {
|
||||
FontVisibility visibility =
|
||||
aAppFont ? FontVisibility::Base
|
||||
: GetVisibilityForFamily(keyName);
|
||||
families.AppendElement(fontlist::Family::InitData(
|
||||
keyName, otherFamilyName,
|
||||
fontlist::Family::kNoIndex, visibility,
|
||||
/*bundled*/ aAppFont, /*badUnderline*/ false));
|
||||
|
||||
return MakeUnique<FaceInitArray>();
|
||||
})
|
||||
->AppendElement(fontlist::Face::InitData{descriptor, 0, false, weight,
|
||||
stretch, style});
|
||||
|
||||
n++;
|
||||
if (n == int(cIndex)) {
|
||||
|
|
|
@ -1588,10 +1588,9 @@ gfxFontEntry* gfxPlatformFontList::FindFontForFamily(
|
|||
|
||||
gfxFontEntry* gfxPlatformFontList::GetOrCreateFontEntry(
|
||||
fontlist::Face* aFace, const fontlist::Family* aFamily) {
|
||||
return mFontEntries.WithEntryHandle(aFace, [&](auto&& entry) {
|
||||
return entry.OrInsertWith([=] { return CreateFontEntry(aFace, aFamily); })
|
||||
.get();
|
||||
});
|
||||
return mFontEntries
|
||||
.GetOrInsertWith(aFace, [=] { return CreateFontEntry(aFace, aFamily); })
|
||||
.get();
|
||||
}
|
||||
|
||||
void gfxPlatformFontList::AddOtherFamilyName(
|
||||
|
|
|
@ -10551,11 +10551,11 @@ void ReflowCountMgr::Add(const char* aName, nsIFrame* aFrame) {
|
|||
NS_ASSERTION(aName != nullptr, "Name shouldn't be null!");
|
||||
|
||||
if (mDumpFrameCounts) {
|
||||
auto* const counter = mCounts.WithEntryHandle(aName, [this](auto&& entry) {
|
||||
return entry
|
||||
.OrInsertWith([this] { return MakeUnique<ReflowCounter>(this); })
|
||||
.get();
|
||||
});
|
||||
auto* const counter =
|
||||
mCounts
|
||||
.GetOrInsertWith(aName,
|
||||
[this] { return MakeUnique<ReflowCounter>(this); })
|
||||
.get();
|
||||
counter->Add();
|
||||
}
|
||||
|
||||
|
@ -10564,16 +10564,16 @@ void ReflowCountMgr::Add(const char* aName, nsIFrame* aFrame) {
|
|||
char key[KEY_BUF_SIZE_FOR_PTR];
|
||||
SprintfLiteral(key, "%p", (void*)aFrame);
|
||||
auto* const counter =
|
||||
mIndiFrameCounts.WithEntryHandle(key, [&](auto&& entry) {
|
||||
return entry
|
||||
.OrInsertWith([&aName, &aFrame, this]() {
|
||||
auto counter = MakeUnique<IndiReflowCounter>(this);
|
||||
counter->mFrame = aFrame;
|
||||
counter->mName.AssignASCII(aName);
|
||||
return counter;
|
||||
})
|
||||
.get();
|
||||
});
|
||||
mIndiFrameCounts
|
||||
.GetOrInsertWith(key,
|
||||
[&aName, &aFrame, this]() {
|
||||
auto counter =
|
||||
MakeUnique<IndiReflowCounter>(this);
|
||||
counter->mFrame = aFrame;
|
||||
counter->mName.AssignASCII(aName);
|
||||
return counter;
|
||||
})
|
||||
.get();
|
||||
// this eliminates extra counts from super classes
|
||||
if (counter && counter->mName.EqualsASCII(aName)) {
|
||||
counter->mCount++;
|
||||
|
|
|
@ -308,9 +308,9 @@ bool nsCounterManager::AddCounterChanges(nsIFrame* aFrame) {
|
|||
|
||||
nsCounterList* nsCounterManager::CounterListFor(nsAtom* aCounterName) {
|
||||
MOZ_ASSERT(aCounterName);
|
||||
return mNames.WithEntryHandle(aCounterName, [](auto&& entry) {
|
||||
return entry.OrInsertWith([] { return MakeUnique<nsCounterList>(); }).get();
|
||||
});
|
||||
return mNames
|
||||
.GetOrInsertWith(aCounterName, [] { return MakeUnique<nsCounterList>(); })
|
||||
.get();
|
||||
}
|
||||
|
||||
void nsCounterManager::RecalcAll() {
|
||||
|
|
|
@ -1354,10 +1354,10 @@ bool nsRefreshDriver::AddImageRequest(imgIRequest* aRequest) {
|
|||
if (delay == 0) {
|
||||
mRequests.PutEntry(aRequest);
|
||||
} else {
|
||||
auto* const start = mStartTable.WithEntryHandle(delay, [](auto&& entry) {
|
||||
return entry.OrInsertWith([] { return MakeUnique<ImageStartData>(); })
|
||||
.get();
|
||||
});
|
||||
auto* const start =
|
||||
mStartTable
|
||||
.GetOrInsertWith(delay, [] { return MakeUnique<ImageStartData>(); })
|
||||
.get();
|
||||
start->mEntries.PutEntry(aRequest);
|
||||
}
|
||||
|
||||
|
|
|
@ -2029,10 +2029,9 @@ void SelectionRangeState::SelectNodesExceptInSubtree(const Position& aStart,
|
|||
static constexpr auto kEllipsis = u"\x2026"_ns;
|
||||
|
||||
nsINode* root = aStart.mNode->SubtreeRoot();
|
||||
auto& start =
|
||||
mPositions.WithEntryHandle(root, [&](auto&& entry) -> Position& {
|
||||
return entry.OrInsertWith([&] { return Position{root, 0}; });
|
||||
});
|
||||
auto& start = mPositions.GetOrInsertWith(root, [&] {
|
||||
return Position{root, 0};
|
||||
});
|
||||
|
||||
bool ellipsizedStart = false;
|
||||
if (auto* text = Text::FromNode(aStart.mNode)) {
|
||||
|
|
|
@ -1279,9 +1279,8 @@ void FontFaceSet::CacheFontLoadability() {
|
|||
if (src.mSourceType != gfxFontFaceSrc::eSourceType_URL) {
|
||||
continue;
|
||||
}
|
||||
mAllowedFontLoads.WithEntryHandle(&src, [&](auto&& entry) {
|
||||
entry.OrInsertWith([&] { return IsFontLoadAllowed(src); });
|
||||
});
|
||||
Unused << mAllowedFontLoads.GetOrInsertWith(
|
||||
&src, [&] { return IsFontLoadAllowed(src); });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -169,38 +169,37 @@ void ImageLoader::AssociateRequestToFrame(imgIRequest* aRequest,
|
|||
}
|
||||
|
||||
auto* const frameSet =
|
||||
mRequestToFrameMap.WithEntryHandle(aRequest, [&](auto&& entry) {
|
||||
return entry
|
||||
.OrInsertWith([&] {
|
||||
mDocument->ImageTracker()->Add(aRequest);
|
||||
mRequestToFrameMap
|
||||
.GetOrInsertWith(
|
||||
aRequest,
|
||||
[&] {
|
||||
mDocument->ImageTracker()->Add(aRequest);
|
||||
|
||||
if (auto entry = sImages->Lookup(aRequest)) {
|
||||
DebugOnly<bool> inserted =
|
||||
entry.Data()->mImageLoaders.EnsureInserted(this);
|
||||
MOZ_ASSERT(inserted);
|
||||
} else {
|
||||
MOZ_ASSERT_UNREACHABLE(
|
||||
"Shouldn't be associating images not in sImages");
|
||||
}
|
||||
if (auto entry = sImages->Lookup(aRequest)) {
|
||||
DebugOnly<bool> inserted =
|
||||
entry.Data()->mImageLoaders.EnsureInserted(this);
|
||||
MOZ_ASSERT(inserted);
|
||||
} else {
|
||||
MOZ_ASSERT_UNREACHABLE(
|
||||
"Shouldn't be associating images not in sImages");
|
||||
}
|
||||
|
||||
if (nsPresContext* presContext = GetPresContext()) {
|
||||
nsLayoutUtils::RegisterImageRequestIfAnimated(
|
||||
presContext, aRequest, nullptr);
|
||||
}
|
||||
return MakeUnique<FrameSet>();
|
||||
})
|
||||
.get();
|
||||
});
|
||||
if (nsPresContext* presContext = GetPresContext()) {
|
||||
nsLayoutUtils::RegisterImageRequestIfAnimated(
|
||||
presContext, aRequest, nullptr);
|
||||
}
|
||||
return MakeUnique<FrameSet>();
|
||||
})
|
||||
.get();
|
||||
|
||||
auto* const requestSet =
|
||||
mFrameToRequestMap.WithEntryHandle(aFrame, [=](auto&& entry) {
|
||||
return entry
|
||||
.OrInsertWith([=]() {
|
||||
aFrame->SetHasImageRequest(true);
|
||||
return MakeUnique<RequestSet>();
|
||||
})
|
||||
.get();
|
||||
});
|
||||
mFrameToRequestMap
|
||||
.GetOrInsertWith(aFrame,
|
||||
[=]() {
|
||||
aFrame->SetHasImageRequest(true);
|
||||
return MakeUnique<RequestSet>();
|
||||
})
|
||||
.get();
|
||||
|
||||
// Add frame to the frameSet, and handle any special processing the
|
||||
// frame might require.
|
||||
|
@ -441,9 +440,8 @@ already_AddRefed<imgRequestProxy> ImageLoader::LoadImage(
|
|||
if (NS_FAILED(rv) || !request) {
|
||||
return nullptr;
|
||||
}
|
||||
sImages->WithEntryHandle(request, [](auto&& entry) {
|
||||
entry.OrInsertWith([] { return MakeUnique<ImageTableEntry>(); });
|
||||
});
|
||||
sImages->GetOrInsertWith(request,
|
||||
[] { return MakeUnique<ImageTableEntry>(); });
|
||||
return request.forget();
|
||||
}
|
||||
|
||||
|
|
|
@ -106,11 +106,10 @@ ShadowParts ShadowParts::Parse(const nsAString& aString) {
|
|||
continue;
|
||||
}
|
||||
nsAtom* second = mapping.second.get();
|
||||
parts.mMappings.WithEntryHandle(mapping.first, [&](auto&& entry) {
|
||||
entry.OrInsertWith([] { return MakeUnique<PartList>(); })
|
||||
->AppendElement(std::move(mapping.second));
|
||||
});
|
||||
parts.mReverseMappings.GetOrInsert(second) = std::move(mapping.first);
|
||||
parts.mMappings
|
||||
.GetOrInsertWith(mapping.first, [] { return MakeUnique<PartList>(); })
|
||||
->AppendElement(std::move(mapping.second));
|
||||
parts.mReverseMappings.Put(second, std::move(mapping.first));
|
||||
}
|
||||
|
||||
return parts;
|
||||
|
|
|
@ -573,9 +573,8 @@ void SharedStyleSheetCache::CancelLoadsForLoader(css::Loader& aLoader) {
|
|||
|
||||
void SharedStyleSheetCache::RegisterLoader(css::Loader& aLoader) {
|
||||
MOZ_ASSERT(aLoader.GetDocument());
|
||||
mLoaderPrincipalRefCnt.WithEntryHandle(
|
||||
aLoader.GetDocument()->NodePrincipal(),
|
||||
[](auto&& entry) { entry.OrInsert(0) += 1; });
|
||||
mLoaderPrincipalRefCnt.GetOrInsert(aLoader.GetDocument()->NodePrincipal(),
|
||||
0) += 1;
|
||||
}
|
||||
|
||||
void SharedStyleSheetCache::UnregisterLoader(css::Loader& aLoader) {
|
||||
|
|
|
@ -135,12 +135,11 @@ nsresult ChildDNSService::AsyncResolveInternal(
|
|||
nsCString key;
|
||||
GetDNSRecordHashKey(hostname, DNSResolverInfo::URL(aResolver), type,
|
||||
aOriginAttributes, flags, originalListenerAddr, key);
|
||||
mPendingRequests.WithEntryHandle(key, [&](auto&& entry) {
|
||||
entry
|
||||
.OrInsertWith(
|
||||
[] { return MakeUnique<nsTArray<RefPtr<DNSRequestSender>>>(); })
|
||||
->AppendElement(sender);
|
||||
});
|
||||
mPendingRequests
|
||||
.GetOrInsertWith(
|
||||
key,
|
||||
[] { return MakeUnique<nsTArray<RefPtr<DNSRequestSender>>>(); })
|
||||
->AppendElement(sender);
|
||||
}
|
||||
|
||||
sender->StartRequest();
|
||||
|
|
|
@ -35,27 +35,24 @@ void TemporaryAccessGrantObserver::Create(PermissionManager* aPM,
|
|||
if (!sObservers) {
|
||||
sObservers = MakeUnique<ObserversTable>();
|
||||
}
|
||||
sObservers->WithEntryHandle(
|
||||
Unused << sObservers->GetOrInsertWith(
|
||||
std::make_pair(nsCOMPtr<nsIPrincipal>(aPrincipal), nsCString(aType)),
|
||||
[&](auto&& entry) {
|
||||
entry.OrInsertWith([&]() -> nsITimer* {
|
||||
// Only create a new observer if we don't have a matching
|
||||
// entry in our hashtable.
|
||||
nsCOMPtr<nsITimer> timer;
|
||||
RefPtr<TemporaryAccessGrantObserver> observer =
|
||||
new TemporaryAccessGrantObserver(aPM, aPrincipal, aType);
|
||||
nsresult rv =
|
||||
NS_NewTimerWithObserver(getter_AddRefs(timer), observer,
|
||||
24 * 60 * 60 * 1000, // 24 hours
|
||||
nsITimer::TYPE_ONE_SHOT);
|
||||
[&]() -> nsCOMPtr<nsITimer> {
|
||||
// Only create a new observer if we don't have a matching
|
||||
// entry in our hashtable.
|
||||
nsCOMPtr<nsITimer> timer;
|
||||
RefPtr<TemporaryAccessGrantObserver> observer =
|
||||
new TemporaryAccessGrantObserver(aPM, aPrincipal, aType);
|
||||
nsresult rv = NS_NewTimerWithObserver(getter_AddRefs(timer), observer,
|
||||
24 * 60 * 60 * 1000, // 24 hours
|
||||
nsITimer::TYPE_ONE_SHOT);
|
||||
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
observer->SetTimer(timer);
|
||||
return timer;
|
||||
}
|
||||
timer->Cancel();
|
||||
return nullptr;
|
||||
});
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
observer->SetTimer(timer);
|
||||
return timer;
|
||||
}
|
||||
timer->Cancel();
|
||||
return nullptr;
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -318,8 +318,7 @@ void UntrustedModulesData::AddNewLoads(
|
|||
continue;
|
||||
}
|
||||
|
||||
mModules.WithEntryHandle(
|
||||
iter.Key(), [&](auto&& addPtr) { addPtr.OrInsert(iter.Data()); });
|
||||
Unused << mModules.GetOrInsert(iter.Key(), iter.Data());
|
||||
}
|
||||
|
||||
// This constant matches the maximum in Telemetry::CombinedStacks
|
||||
|
|
Загрузка…
Ссылка в новой задаче