diff --git a/docshell/base/BrowsingContextGroup.cpp b/docshell/base/BrowsingContextGroup.cpp index 382a23d7b774..9950235f8be2 100644 --- a/docshell/base/BrowsingContextGroup.cpp +++ b/docshell/base/BrowsingContextGroup.cpp @@ -34,11 +34,9 @@ already_AddRefed BrowsingContextGroup::GetOrCreate( ClearOnShutdown(&sBrowsingContextGroups); } - return sBrowsingContextGroups->WithEntryHandle(aId, [&aId](auto&& entry) { - RefPtr group = entry.OrInsertWith( - [&aId] { return do_AddRef(new BrowsingContextGroup(aId)); }); - return group.forget(); - }); + RefPtr group = sBrowsingContextGroups->GetOrInsertWith( + aId, [&aId] { return do_AddRef(new BrowsingContextGroup(aId)); }); + return group.forget(); } already_AddRefed BrowsingContextGroup::Create() { diff --git a/dom/animation/EffectCompositor.cpp b/dom/animation/EffectCompositor.cpp index 885f8ce07137..737c5c1b1c02 100644 --- a/dom/animation/EffectCompositor.cpp +++ b/dom/animation/EffectCompositor.cpp @@ -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); } diff --git a/dom/base/CustomElementRegistry.cpp b/dom/base/CustomElementRegistry.cpp index ad886774db25..2a1b002d4f34 100644 --- a/dom/base/CustomElementRegistry.cpp +++ b/dom/base/CustomElementRegistry.cpp @@ -1105,12 +1105,8 @@ already_AddRefed CustomElementRegistry::WhenDefined( return promise.forget(); } - return mWhenDefinedPromiseMap - .WithEntryHandle(nameAtom, - [&promise](auto&& entry) -> RefPtr { - return entry.OrInsert(std::move(promise)); - }) - .forget(); + return do_AddRef( + mWhenDefinedPromiseMap.GetOrInsert(nameAtom, std::move(promise))); } namespace { diff --git a/dom/base/Document.h b/dom/base/Document.h index b0ac1f1ca7d1..5a1bd2dedad2 100644 --- a/dom/base/Document.h +++ b/dom/base/Document.h @@ -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(aFrom)).get(); - }); + return mTable.GetOrInsertWith(aSelector, std::forward(aFrom)).get(); } ~SelectorCache(); diff --git a/dom/base/DocumentOrShadowRoot.cpp b/dom/base/DocumentOrShadowRoot.cpp index f8629d5916cf..e21fd01f3df6 100644 --- a/dom/base/DocumentOrShadowRoot.cpp +++ b/dom/base/DocumentOrShadowRoot.cpp @@ -218,11 +218,8 @@ void DocumentOrShadowRoot::CloneAdoptedSheetsFrom( MOZ_ASSERT(clonedSheetMap); for (const StyleSheet* sheet : aSource.mAdoptedStyleSheets) { - RefPtr clone = clonedSheetMap->WithEntryHandle( - sheet, [&sheet, &ownerDoc](auto&& entry) { - return entry.OrInsertWith( - [&] { return sheet->CloneAdoptedSheet(ownerDoc); }); - }); + RefPtr clone = clonedSheetMap->GetOrInsertWith( + sheet, [&] { return sheet->CloneAdoptedSheet(ownerDoc); }); MOZ_ASSERT(clone); MOZ_DIAGNOSTIC_ASSERT(clone->ConstructorDocumentMatches(ownerDoc)); DebugOnly 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(); }) - .get(); - }); + return mRadioGroups + .GetOrInsertWith(aName, [] { return MakeUnique(); }) + .get(); } int32_t DocumentOrShadowRoot::StyleOrderIndexOfSheet( diff --git a/dom/base/Element.cpp b/dom/base/Element.cpp index 08ab1587dc97..f1ea519eb81b 100644 --- a/dom/base/Element.cpp +++ b/dom/base/Element.cpp @@ -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( diff --git a/dom/base/ResizeObserver.cpp b/dom/base/ResizeObserver.cpp index 1fd2f244d577..7dd6a427dc46 100644 --- a/dom/base/ResizeObserver.cpp +++ b/dom/base/ResizeObserver.cpp @@ -150,10 +150,7 @@ void ResizeObserver::Observe(Element& aTarget, mDocument->AddResizeObserver(*this); } - auto& observation = mObservationMap.WithEntryHandle( - &aTarget, [](auto&& entry) -> RefPtr& { - 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 diff --git a/dom/base/nsDOMMutationObserver.cpp b/dom/base/nsDOMMutationObserver.cpp index f57a04f5ffc2..2aa35b41e8e9 100644 --- a/dom/base/nsDOMMutationObserver.cpp +++ b/dom/base/nsDOMMutationObserver.cpp @@ -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>(); - }) - .get(); - }); + Observer() + ->mTransientReceivers + .GetOrInsertWith( + aChild, + [&isNewEntry] { + isNewEntry = true; + return MakeUnique>(); + }) + .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>(); - }) - .get(); - }); + ob->mTransientReceivers + .GetOrInsertWith( + removed, + [] { return MakeUnique>(); }) + .get(); for (uint32_t k = 0; k < allObservers.Length(); ++k) { nsMutationReceiver* r = allObservers[k]; nsMutationReceiver* orig = r->GetParent() ? r->GetParent() : r; diff --git a/dom/base/nsFrameMessageManager.cpp b/dom/base/nsFrameMessageManager.cpp index 7677e2345383..e08cfdbb7f8f 100644 --- a/dom/base/nsFrameMessageManager.cpp +++ b/dom/base/nsFrameMessageManager.cpp @@ -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>(); - }) - .get(); - }); + mListeners + .GetOrInsertWith( + aMessageName, + [] { + return MakeUnique< + nsAutoTObserverArray>(); + }) + .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>(); - }) - .get(); - }); + mListeners + .GetOrInsertWith( + aMessageName, + [] { + return MakeUnique< + nsAutoTObserverArray>(); + }) + .get(); uint32_t len = listeners->Length(); for (uint32_t i = 0; i < len; ++i) { if (listeners->ElementAt(i).mWeakListener == weak) { diff --git a/dom/base/nsGlobalWindowInner.cpp b/dom/base/nsGlobalWindowInner.cpp index 3eda4135c827..2da36ad2b9c8 100644 --- a/dom/base/nsGlobalWindowInner.cpp +++ b/dom/base/nsGlobalWindowInner.cpp @@ -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(MessageManager()); + }) + .get(); } void nsGlobalWindowInner::InitWasOffline() { mWasOffline = NS_IsOffline(); } diff --git a/dom/broadcastchannel/BroadcastChannelService.cpp b/dom/broadcastchannel/BroadcastChannelService.cpp index 610b8452374d..8b475cc2952b 100644 --- a/dom/broadcastchannel/BroadcastChannelService.cpp +++ b/dom/broadcastchannel/BroadcastChannelService.cpp @@ -82,12 +82,11 @@ void BroadcastChannelService::RegisterActor( MOZ_ASSERT(aParent); auto* const parents = - mAgents.WithEntryHandle(aOriginChannelKey, [](auto&& entry) { - return entry - .OrInsertWith( - [] { return MakeUnique>(); }) - .get(); - }); + mAgents + .GetOrInsertWith( + aOriginChannelKey, + [] { return MakeUnique>(); }) + .get(); MOZ_ASSERT(!parents->Contains(aParent)); parents->AppendElement(aParent); diff --git a/dom/commandhandler/nsCommandManager.cpp b/dom/commandhandler/nsCommandManager.cpp index 5490482e38f7..ecf1d391ada8 100644 --- a/dom/commandhandler/nsCommandManager.cpp +++ b/dom/commandhandler/nsCommandManager.cpp @@ -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(); }) - .get(); - }); + mObserversTable + .GetOrInsertWith(aCommandToObserve, + [] { return mozilla::MakeUnique(); }) + .get(); // need to check that this command observer hasn't already been registered int32_t existingIndex = commandObservers->IndexOf(aCommandObserver); diff --git a/dom/events/EventListenerService.cpp b/dom/events/EventListenerService.cpp index d10643d07574..f8c21e72d50b 100644 --- a/dom/events/EventListenerService.cpp +++ b/dom/events/EventListenerService.cpp @@ -374,12 +374,10 @@ void EventListenerService::NotifyAboutMainThreadListenerChangeInternal( } RefPtr 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(aTarget); + mPendingListenerChanges->AppendElement(c); + return c; }); changes->AddChangedListenerName(aName); } diff --git a/dom/events/EventStateManager.cpp b/dom/events/EventStateManager.cpp index 554032036701..33b2a7f024ff 100644 --- a/dom/events/EventStateManager.cpp +++ b/dom/events/EventStateManager.cpp @@ -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 */ diff --git a/dom/html/HTMLAllCollection.cpp b/dom/html/HTMLAllCollection.cpp index 487a6aca46d4..445c8cbc0a85 100644 --- a/dom/html/HTMLAllCollection.cpp +++ b/dom/html/HTMLAllCollection.cpp @@ -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 id = NS_Atomize(aID); - return new nsContentList(mDocument, DocAllResultMatch, nullptr, - nullptr, true, id); - }) - .get(); - }); + return mNamedMap + .GetOrInsertWith(aID, + [this, &aID] { + RefPtr id = NS_Atomize(aID); + return new nsContentList(mDocument, DocAllResultMatch, + nullptr, nullptr, true, id); + }) + .get(); } void HTMLAllCollection::NamedGetter( diff --git a/dom/html/HTMLFormElement.cpp b/dom/html/HTMLFormElement.cpp index fb336d6701a3..f8498559ca68 100644 --- a/dom/html/HTMLFormElement.cpp +++ b/dom/html/HTMLFormElement.cpp @@ -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; } } diff --git a/dom/localstorage/ActorsParent.cpp b/dom/localstorage/ActorsParent.cpp index c0fc33b27a2c..d37350938a67 100644 --- a/dom/localstorage/ActorsParent.cpp +++ b/dom/localstorage/ActorsParent.cpp @@ -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) { diff --git a/dom/media/ogg/OggCodecState.cpp b/dom/media/ogg/OggCodecState.cpp index 8a3dc6129500..5ddc19f243fa 100644 --- a/dom/media/ogg/OggCodecState.cpp +++ b/dom/media/ogg/OggCodecState.cpp @@ -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(msgHead + nameLen, - msgProbe - msgHead - nameLen); - }); - }); + Unused << field->mValuesStore.GetOrInsertWith( + eHeaderType, [i, msgHead, msgProbe]() { + uint32_t nameLen = + strlen(kFieldTypeMaps[i].mPatternToRecognize); + return MakeUnique(msgHead + nameLen, + msgProbe - msgHead - nameLen); + }); isContentTypeParsed = i == 0 ? true : isContentTypeParsed; } break; diff --git a/dom/payments/PaymentRequestManager.cpp b/dom/payments/PaymentRequestManager.cpp index 8d502f21fc6c..20c9b1e9736f 100644 --- a/dom/payments/PaymentRequestManager.cpp +++ b/dom/payments/PaymentRequestManager.cpp @@ -380,8 +380,7 @@ nsresult PaymentRequestManager::SendRequestPayment( } if (aResponseExpected) { - mActivePayments.WithEntryHandle(aRequest, - [](auto&& count) { ++count.OrInsert(0); }); + ++mActivePayments.GetOrInsert(aRequest, 0); } return NS_OK; } diff --git a/dom/quota/ActorsParent.cpp b/dom/quota/ActorsParent.cpp index 4264bb2f6b6b..4a3f6ca1fc4f 100644 --- a/dom/quota/ActorsParent.cpp +++ b/dom/quota/ActorsParent.cpp @@ -4368,15 +4368,12 @@ already_AddRefed QuotaManager::GetQuotaObject( // pointer directly since QuotaObject::AddRef would try to acquire the same // mutex. const NotNull 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() { diff --git a/dom/serviceworkers/ServiceWorkerManager.cpp b/dom/serviceworkers/ServiceWorkerManager.cpp index 65f8bf695573..1acf7ff2ca8c 100644 --- a/dom/serviceworkers/ServiceWorkerManager.cpp +++ b/dom/serviceworkers/ServiceWorkerManager.cpp @@ -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(); }) - .get(); - }); + swm->mRegistrationInfos + .GetOrInsertWith( + scopeKey, + [] { return MakeUnique(); }) + .get(); data->mScopeContainer.InsertScope(aScope); data->mInfos.Put(aScope, RefPtr{aInfo}); diff --git a/dom/storage/SessionStorageManager.cpp b/dom/storage/SessionStorageManager.cpp index 51b12c2ba4de..8c19152d665c 100644 --- a/dom/storage/SessionStorageManager.cpp +++ b/dom/storage/SessionStorageManager.cpp @@ -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() { diff --git a/dom/workers/RuntimeService.cpp b/dom/workers/RuntimeService.cpp index e7df6ded13a3..0bfdf3cc978b 100644 --- a/dom/workers/RuntimeService.cpp +++ b/dom/workers/RuntimeService.cpp @@ -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(); - 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(); + 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>(1); }) - .get(); - }); + if (auto* const windowArray = + mWindowMap + .GetOrInsertWith( + window, + [] { return MakeUnique>(1); }) + .get(); !windowArray->Contains(&aWorkerPrivate)) { windowArray->AppendElement(&aWorkerPrivate); } else { diff --git a/gfx/gl/GLContextProviderEGL.cpp b/gfx/gl/GLContextProviderEGL.cpp index f7c2bde0a866..64cb450f77a9 100644 --- a/gfx/gl/GLContextProviderEGL.cpp +++ b/gfx/gl/GLContextProviderEGL.cpp @@ -867,11 +867,9 @@ EGLSurface GLContextEGL::CreateWaylandBufferSurface( config, reinterpret_cast(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 } diff --git a/gfx/thebes/gfxFcPlatformFontList.cpp b/gfx/thebes/gfxFcPlatformFontList.cpp index d6b60aa210a0..e78a0a8038ea 100644 --- a/gfx/thebes/gfxFcPlatformFontList.cpp +++ b/gfx/thebes/gfxFcPlatformFontList.cpp @@ -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()); - 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(); + }) + .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()); - 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(); + }) + ->AppendElement(fontlist::Face::InitData{descriptor, 0, false, weight, + stretch, style}); n++; if (n == int(cIndex)) { diff --git a/gfx/thebes/gfxPlatformFontList.cpp b/gfx/thebes/gfxPlatformFontList.cpp index 269b7519aabc..bc2ed9342f60 100644 --- a/gfx/thebes/gfxPlatformFontList.cpp +++ b/gfx/thebes/gfxPlatformFontList.cpp @@ -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( diff --git a/layout/base/PresShell.cpp b/layout/base/PresShell.cpp index 786bf015ecaf..6d863481b253 100644 --- a/layout/base/PresShell.cpp +++ b/layout/base/PresShell.cpp @@ -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(this); }) - .get(); - }); + auto* const counter = + mCounts + .GetOrInsertWith(aName, + [this] { return MakeUnique(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(this); - counter->mFrame = aFrame; - counter->mName.AssignASCII(aName); - return counter; - }) - .get(); - }); + mIndiFrameCounts + .GetOrInsertWith(key, + [&aName, &aFrame, this]() { + auto counter = + MakeUnique(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++; diff --git a/layout/base/nsCounterManager.cpp b/layout/base/nsCounterManager.cpp index 0c937d3250d7..295c9ff9b384 100644 --- a/layout/base/nsCounterManager.cpp +++ b/layout/base/nsCounterManager.cpp @@ -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(); }).get(); - }); + return mNames + .GetOrInsertWith(aCounterName, [] { return MakeUnique(); }) + .get(); } void nsCounterManager::RecalcAll() { diff --git a/layout/base/nsRefreshDriver.cpp b/layout/base/nsRefreshDriver.cpp index 26e698f88b99..bedd17008d1b 100644 --- a/layout/base/nsRefreshDriver.cpp +++ b/layout/base/nsRefreshDriver.cpp @@ -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(); }) - .get(); - }); + auto* const start = + mStartTable + .GetOrInsertWith(delay, [] { return MakeUnique(); }) + .get(); start->mEntries.PutEntry(aRequest); } diff --git a/layout/printing/nsPrintJob.cpp b/layout/printing/nsPrintJob.cpp index f84c78fd8105..6ef7fcf27a92 100644 --- a/layout/printing/nsPrintJob.cpp +++ b/layout/printing/nsPrintJob.cpp @@ -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)) { diff --git a/layout/style/FontFaceSet.cpp b/layout/style/FontFaceSet.cpp index f2b454c7a02a..64cf3ac4d4e7 100644 --- a/layout/style/FontFaceSet.cpp +++ b/layout/style/FontFaceSet.cpp @@ -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); }); } } } diff --git a/layout/style/ImageLoader.cpp b/layout/style/ImageLoader.cpp index f89a7b45a391..30c9c749dcc1 100644 --- a/layout/style/ImageLoader.cpp +++ b/layout/style/ImageLoader.cpp @@ -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 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 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(); - }) - .get(); - }); + if (nsPresContext* presContext = GetPresContext()) { + nsLayoutUtils::RegisterImageRequestIfAnimated( + presContext, aRequest, nullptr); + } + return MakeUnique(); + }) + .get(); auto* const requestSet = - mFrameToRequestMap.WithEntryHandle(aFrame, [=](auto&& entry) { - return entry - .OrInsertWith([=]() { - aFrame->SetHasImageRequest(true); - return MakeUnique(); - }) - .get(); - }); + mFrameToRequestMap + .GetOrInsertWith(aFrame, + [=]() { + aFrame->SetHasImageRequest(true); + return MakeUnique(); + }) + .get(); // Add frame to the frameSet, and handle any special processing the // frame might require. @@ -441,9 +440,8 @@ already_AddRefed ImageLoader::LoadImage( if (NS_FAILED(rv) || !request) { return nullptr; } - sImages->WithEntryHandle(request, [](auto&& entry) { - entry.OrInsertWith([] { return MakeUnique(); }); - }); + sImages->GetOrInsertWith(request, + [] { return MakeUnique(); }); return request.forget(); } diff --git a/layout/style/ShadowParts.cpp b/layout/style/ShadowParts.cpp index d406b0f13c34..c80ed254dfe3 100644 --- a/layout/style/ShadowParts.cpp +++ b/layout/style/ShadowParts.cpp @@ -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(); }) - ->AppendElement(std::move(mapping.second)); - }); - parts.mReverseMappings.GetOrInsert(second) = std::move(mapping.first); + parts.mMappings + .GetOrInsertWith(mapping.first, [] { return MakeUnique(); }) + ->AppendElement(std::move(mapping.second)); + parts.mReverseMappings.Put(second, std::move(mapping.first)); } return parts; diff --git a/layout/style/SharedStyleSheetCache.cpp b/layout/style/SharedStyleSheetCache.cpp index 7c23b92c3ffe..2da7b42e62c1 100644 --- a/layout/style/SharedStyleSheetCache.cpp +++ b/layout/style/SharedStyleSheetCache.cpp @@ -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) { diff --git a/netwerk/dns/ChildDNSService.cpp b/netwerk/dns/ChildDNSService.cpp index d05fcd8f9a6d..3f3cf051a5f7 100644 --- a/netwerk/dns/ChildDNSService.cpp +++ b/netwerk/dns/ChildDNSService.cpp @@ -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>>(); }) - ->AppendElement(sender); - }); + mPendingRequests + .GetOrInsertWith( + key, + [] { return MakeUnique>>(); }) + ->AppendElement(sender); } sender->StartRequest(); diff --git a/toolkit/components/antitracking/TemporaryAccessGrantObserver.cpp b/toolkit/components/antitracking/TemporaryAccessGrantObserver.cpp index 1c8bfa22a659..7011ac41434a 100644 --- a/toolkit/components/antitracking/TemporaryAccessGrantObserver.cpp +++ b/toolkit/components/antitracking/TemporaryAccessGrantObserver.cpp @@ -35,27 +35,24 @@ void TemporaryAccessGrantObserver::Create(PermissionManager* aPM, if (!sObservers) { sObservers = MakeUnique(); } - sObservers->WithEntryHandle( + Unused << sObservers->GetOrInsertWith( std::make_pair(nsCOMPtr(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 timer; - RefPtr 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 { + // Only create a new observer if we don't have a matching + // entry in our hashtable. + nsCOMPtr timer; + RefPtr 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; }); } diff --git a/toolkit/xre/UntrustedModulesData.cpp b/toolkit/xre/UntrustedModulesData.cpp index d3b22a8867f9..606069a0a999 100644 --- a/toolkit/xre/UntrustedModulesData.cpp +++ b/toolkit/xre/UntrustedModulesData.cpp @@ -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