Bug 1693306 - Simplify some uses of LookupOrInsertWith by GetOrInsertNew. r=xpcom-reviewers,necko-reviewers,dragana,nika

Differential Revision: https://phabricator.services.mozilla.com/D105479
This commit is contained in:
Simon Giesecke 2021-02-26 09:22:54 +00:00
parent be7dc83fa6
commit 0b443059fd
35 changed files with 50 additions and 190 deletions

View File

@ -164,15 +164,9 @@ inline DocAccessible::AttrRelProviders* DocAccessible::GetOrCreateRelProviders(
dom::DocumentOrShadowRoot* docOrShadowRoot = dom::DocumentOrShadowRoot* docOrShadowRoot =
aElement->GetUncomposedDocOrConnectedShadowRoot(); aElement->GetUncomposedDocOrConnectedShadowRoot();
DependentIDsHashtable* hash = DependentIDsHashtable* hash =
mDependentIDsHashes mDependentIDsHashes.GetOrInsertNew(docOrShadowRoot);
.LookupOrInsertWith(
docOrShadowRoot,
[] { return MakeUnique<DependentIDsHashtable>(); })
.get();
return hash return hash->GetOrInsertNew(aID);
->LookupOrInsertWith(aID, [] { return MakeUnique<AttrRelProviders>(); })
.get();
} }
inline void DocAccessible::RemoveRelProvidersIfEmpty(dom::Element* aElement, inline void DocAccessible::RemoveRelProvidersIfEmpty(dom::Element* aElement,

View File

@ -752,10 +752,7 @@ nsRadioGroupStruct* DocumentOrShadowRoot::GetRadioGroup(
nsRadioGroupStruct* DocumentOrShadowRoot::GetOrCreateRadioGroup( nsRadioGroupStruct* DocumentOrShadowRoot::GetOrCreateRadioGroup(
const nsAString& aName) { const nsAString& aName) {
return mRadioGroups return mRadioGroups.GetOrInsertNew(aName);
.LookupOrInsertWith(aName,
[] { return MakeUnique<nsRadioGroupStruct>(); })
.get();
} }
int32_t DocumentOrShadowRoot::StyleOrderIndexOfSheet( int32_t DocumentOrShadowRoot::StyleOrderIndexOfSheet(

View File

@ -201,11 +201,7 @@ EventSourceEventService::AddListener(uint64_t aInnerWindowID,
} }
++mCountListeners; ++mCountListeners;
WindowListener* listener = WindowListener* listener = mWindows.GetOrInsertNew(aInnerWindowID);
mWindows
.LookupOrInsertWith(aInnerWindowID,
[] { return MakeUnique<WindowListener>(); })
.get();
listener->mListeners.AppendElement(aListener); listener->mListeners.AppendElement(aListener);

View File

@ -1039,11 +1039,7 @@ void nsAutoMutationBatch::Done() {
if (allObservers.Length()) { if (allObservers.Length()) {
auto* const transientReceivers = auto* const transientReceivers =
ob->mTransientReceivers ob->mTransientReceivers.GetOrInsertNew(removed);
.LookupOrInsertWith(
removed,
[] { return MakeUnique<nsCOMArray<nsMutationReceiver>>(); })
.get();
for (uint32_t k = 0; k < allObservers.Length(); ++k) { for (uint32_t k = 0; k < allObservers.Length(); ++k) {
nsMutationReceiver* r = allObservers[k]; nsMutationReceiver* r = allObservers[k];
nsMutationReceiver* orig = r->GetParent() ? r->GetParent() : r; nsMutationReceiver* orig = r->GetParent() ? r->GetParent() : r;

View File

@ -239,15 +239,7 @@ void nsFrameMessageManager::AddMessageListener(const nsAString& aMessageName,
MessageListener& aListener, MessageListener& aListener,
bool aListenWhenClosed, bool aListenWhenClosed,
ErrorResult& aError) { ErrorResult& aError) {
auto* const listeners = auto* const listeners = mListeners.GetOrInsertNew(aMessageName);
mListeners
.LookupOrInsertWith(
aMessageName,
[] {
return MakeUnique<
nsAutoTObserverArray<nsMessageListenerInfo, 1>>();
})
.get();
uint32_t len = listeners->Length(); uint32_t len = listeners->Length();
for (uint32_t i = 0; i < len; ++i) { for (uint32_t i = 0; i < len; ++i) {
MessageListener* strongListener = listeners->ElementAt(i).mStrongListener; MessageListener* strongListener = listeners->ElementAt(i).mStrongListener;
@ -314,15 +306,7 @@ void nsFrameMessageManager::AddWeakMessageListener(
} }
#endif #endif
auto* const listeners = auto* const listeners = mListeners.GetOrInsertNew(aMessageName);
mListeners
.LookupOrInsertWith(
aMessageName,
[] {
return MakeUnique<
nsAutoTObserverArray<nsMessageListenerInfo, 1>>();
})
.get();
uint32_t len = listeners->Length(); uint32_t len = listeners->Length();
for (uint32_t i = 0; i < len; ++i) { for (uint32_t i = 0; i < len; ++i) {
if (listeners->ElementAt(i).mWeakListener == weak) { if (listeners->ElementAt(i).mWeakListener == weak) {

View File

@ -81,12 +81,7 @@ void BroadcastChannelService::RegisterActor(
AssertIsOnBackgroundThread(); AssertIsOnBackgroundThread();
MOZ_ASSERT(aParent); MOZ_ASSERT(aParent);
auto* const parents = auto* const parents = mAgents.GetOrInsertNew(aOriginChannelKey);
mAgents
.LookupOrInsertWith(
aOriginChannelKey,
[] { return MakeUnique<nsTArray<BroadcastChannelParent*>>(); })
.get();
MOZ_ASSERT(!parents->Contains(aParent)); MOZ_ASSERT(!parents->Contains(aParent));
parents->AppendElement(aParent); parents->AppendElement(aParent);

View File

@ -81,11 +81,7 @@ nsCommandManager::AddCommandObserver(nsIObserver* aCommandObserver,
// for each command in the table, we make a list of observers for that command // for each command in the table, we make a list of observers for that command
auto* const commandObservers = auto* const commandObservers =
mObserversTable mObserversTable.GetOrInsertNew(aCommandToObserve);
.LookupOrInsertWith(
aCommandToObserve,
[] { return mozilla::MakeUnique<ObserverList>(); })
.get();
// need to check that this command observer hasn't already been registered // need to check that this command observer hasn't already been registered
int32_t existingIndex = commandObservers->IndexOf(aCommandObserver); int32_t existingIndex = commandObservers->IndexOf(aCommandObserver);

View File

@ -7627,13 +7627,7 @@ nsresult DatabaseConnection::UpdateRefcountFunction::ProcessValue(
MOZ_ASSERT(id > 0); MOZ_ASSERT(id > 0);
const auto entry = const auto entry =
WrapNotNull(mFileInfoEntries WrapNotNull(mFileInfoEntries.GetOrInsertNew(id, file.FileInfoPtr()));
.LookupOrInsertWith(id,
[&file] {
return MakeUnique<FileInfoEntry>(
file.FileInfoPtr());
})
.get());
if (mInSavepoint) { if (mInSavepoint) {
mSavepointEntriesIndex.InsertOrUpdate(id, entry); mSavepointEntriesIndex.InsertOrUpdate(id, entry);

View File

@ -3228,11 +3228,7 @@ bool RecvPBackgroundLSObserverConstructor(PBackgroundLSObserverParent* aActor,
const auto notNullObserver = WrapNotNull(observer.get()); const auto notNullObserver = WrapNotNull(observer.get());
nsTArray<NotNull<Observer*>>* const array = nsTArray<NotNull<Observer*>>* const array =
gObservers gObservers->GetOrInsertNew(notNullObserver->Origin());
->LookupOrInsertWith(
notNullObserver->Origin(),
[] { return MakeUnique<nsTArray<NotNull<Observer*>>>(); })
.get();
array->AppendElement(notNullObserver); array->AppendElement(notNullObserver);
if (RefPtr<Datastore> datastore = GetDatastore(observer->Origin())) { if (RefPtr<Datastore> datastore = GetDatastore(observer->Origin())) {

View File

@ -2792,11 +2792,7 @@ RefPtr<MediaManager::StreamPromise> MediaManager::GetUserMedia(
// Add a WindowID cross-reference so OnNavigation can tear // Add a WindowID cross-reference so OnNavigation can tear
// things down // things down
nsTArray<nsString>* const array = nsTArray<nsString>* const array =
self->mCallIds self->mCallIds.GetOrInsertNew(windowID);
.LookupOrInsertWith(
windowID,
[] { return MakeUnique<nsTArray<nsString>>(); })
.get();
array->AppendElement(callID); array->AppendElement(callID);
nsCOMPtr<nsIObserverService> obs = services::GetObserverService(); nsCOMPtr<nsIObserverService> obs = services::GetObserverService();

View File

@ -13,10 +13,7 @@ class GMPMemoryStorage : public GMPStorage {
GMPErr Open(const nsCString& aRecordName) override { GMPErr Open(const nsCString& aRecordName) override {
MOZ_ASSERT(!IsOpen(aRecordName)); MOZ_ASSERT(!IsOpen(aRecordName));
Record* record = mRecords Record* record = mRecords.GetOrInsertNew(aRecordName);
.LookupOrInsertWith(
aRecordName, [] { return MakeUnique<Record>(); })
.get();
record->mIsOpen = true; record->mIsOpen = true;
return GMPNoErr; return GMPNoErr;
} }

View File

@ -79,10 +79,8 @@ class PresentationServiceBase {
return; return;
} }
mRespondingSessionIds mRespondingSessionIds.GetOrInsertNew(aWindowId)->AppendElement(
.LookupOrInsertWith(aWindowId, nsString(aSessionId));
[] { return MakeUnique<nsTArray<nsString>>(); })
->AppendElement(nsString(aSessionId));
mRespondingWindowIds.InsertOrUpdate(aSessionId, aWindowId); mRespondingWindowIds.InsertOrUpdate(aSessionId, aWindowId);
} }
@ -227,10 +225,8 @@ class PresentationServiceBase {
for (uint32_t i = 0; i < entry->mListeners.Length(); ++i) { for (uint32_t i = 0; i < entry->mListeners.Length(); ++i) {
nsIPresentationAvailabilityListener* listener = nsIPresentationAvailabilityListener* listener =
entry->mListeners.ObjectAt(i); entry->mListeners.ObjectAt(i);
availabilityListenerTable availabilityListenerTable.GetOrInsertNew(listener)->AppendElement(
.LookupOrInsertWith( it.Key());
listener, [] { return MakeUnique<nsTArray<nsString>>(); })
->AppendElement(it.Key());
} }
} }
} }

View File

@ -6674,11 +6674,7 @@ already_AddRefed<GroupInfo> QuotaManager::LockedGetOrCreateGroupInfo(
mQuotaMutex.AssertCurrentThreadOwns(); mQuotaMutex.AssertCurrentThreadOwns();
MOZ_ASSERT(aPersistenceType != PERSISTENCE_TYPE_PERSISTENT); MOZ_ASSERT(aPersistenceType != PERSISTENCE_TYPE_PERSISTENT);
GroupInfoPair* const pair = GroupInfoPair* const pair = mGroupInfoPairs.GetOrInsertNew(aGroup);
mGroupInfoPairs
.LookupOrInsertWith(aGroup,
[] { return MakeUnique<GroupInfoPair>(); })
.get();
RefPtr<GroupInfo> groupInfo = pair->LockedGetGroupInfo(aPersistenceType); RefPtr<GroupInfo> groupInfo = pair->LockedGetGroupInfo(aPersistenceType);
if (!groupInfo) { if (!groupInfo) {

View File

@ -1906,12 +1906,7 @@ void ServiceWorkerManager::AddScopeAndRegistration(
MOZ_ASSERT(!scopeKey.IsEmpty()); MOZ_ASSERT(!scopeKey.IsEmpty());
auto* const data = auto* const data = swm->mRegistrationInfos.GetOrInsertNew(scopeKey);
swm->mRegistrationInfos
.LookupOrInsertWith(
scopeKey,
[] { return MakeUnique<RegistrationDataPerPrincipal>(); })
.get();
data->mScopeContainer.InsertScope(aScope); data->mScopeContainer.InsertScope(aScope);
data->mInfos.InsertOrUpdate(aScope, RefPtr{aInfo}); data->mInfos.InsertOrUpdate(aScope, RefPtr{aInfo});

View File

@ -1463,11 +1463,7 @@ mozilla::ipc::IPCResult RecvPBackgroundLocalStorageCacheConstructor(
gLocalStorageCacheParents = new LocalStorageCacheParentHashtable(); gLocalStorageCacheParents = new LocalStorageCacheParentHashtable();
} }
gLocalStorageCacheParents gLocalStorageCacheParents->GetOrInsertNew(aOriginKey)->AppendElement(actor);
->LookupOrInsertWith(
aOriginKey,
[] { return MakeUnique<nsTArray<LocalStorageCacheParent*>>(); })
->AppendElement(actor);
// We are currently trusting the content process not to lie to us. It is // We are currently trusting the content process not to lie to us. It is
// future work to consult the ClientManager to determine whether this is a // future work to consult the ClientManager to determine whether this is a

View File

@ -1222,12 +1222,7 @@ bool RuntimeService::RegisterWorker(WorkerPrivate& aWorkerPrivate) {
if (!isServiceWorker) { if (!isServiceWorker) {
// Service workers are excluded since their lifetime is separate from // Service workers are excluded since their lifetime is separate from
// that of dom windows. // that of dom windows.
if (auto* const windowArray = if (auto* const windowArray = mWindowMap.GetOrInsertNew(window, 1);
mWindowMap
.LookupOrInsertWith(
window,
[] { return MakeUnique<nsTArray<WorkerPrivate*>>(1); })
.get();
!windowArray->Contains(&aWorkerPrivate)) { !windowArray->Contains(&aWorkerPrivate)) {
windowArray->AppendElement(&aWorkerPrivate); windowArray->AppendElement(&aWorkerPrivate);
} else { } else {

View File

@ -10551,11 +10551,7 @@ void ReflowCountMgr::Add(const char* aName, nsIFrame* aFrame) {
NS_ASSERTION(aName != nullptr, "Name shouldn't be null!"); NS_ASSERTION(aName != nullptr, "Name shouldn't be null!");
if (mDumpFrameCounts) { if (mDumpFrameCounts) {
auto* const counter = auto* const counter = mCounts.GetOrInsertNew(aName, this);
mCounts
.LookupOrInsertWith(
aName, [this] { return MakeUnique<ReflowCounter>(this); })
.get();
counter->Add(); counter->Add();
} }

View File

@ -308,10 +308,7 @@ bool nsCounterManager::AddCounterChanges(nsIFrame* aFrame) {
nsCounterList* nsCounterManager::CounterListFor(nsAtom* aCounterName) { nsCounterList* nsCounterManager::CounterListFor(nsAtom* aCounterName) {
MOZ_ASSERT(aCounterName); MOZ_ASSERT(aCounterName);
return mNames return mNames.GetOrInsertNew(aCounterName);
.LookupOrInsertWith(aCounterName,
[] { return MakeUnique<nsCounterList>(); })
.get();
} }
void nsCounterManager::RecalcAll() { void nsCounterManager::RecalcAll() {

View File

@ -1354,11 +1354,7 @@ bool nsRefreshDriver::AddImageRequest(imgIRequest* aRequest) {
if (delay == 0) { if (delay == 0) {
mRequests.PutEntry(aRequest); mRequests.PutEntry(aRequest);
} else { } else {
auto* const start = auto* const start = mStartTable.GetOrInsertNew(delay);
mStartTable
.LookupOrInsertWith(delay,
[] { return MakeUnique<ImageStartData>(); })
.get();
start->mEntries.PutEntry(aRequest); start->mEntries.PutEntry(aRequest);
} }

View File

@ -2029,9 +2029,10 @@ void SelectionRangeState::SelectNodesExceptInSubtree(const Position& aStart,
static constexpr auto kEllipsis = u"\x2026"_ns; static constexpr auto kEllipsis = u"\x2026"_ns;
nsINode* root = aStart.mNode->SubtreeRoot(); nsINode* root = aStart.mNode->SubtreeRoot();
auto& start = mPositions.LookupOrInsertWith(root, [&] { auto& start =
return Position{root, 0}; mPositions.WithEntryHandle(root, [&](auto&& entry) -> Position& {
}); return entry.OrInsertWith([&] { return Position{root, 0}; });
});
bool ellipsizedStart = false; bool ellipsizedStart = false;
if (auto* text = Text::FromNode(aStart.mNode)) { if (auto* text = Text::FromNode(aStart.mNode)) {

View File

@ -440,8 +440,7 @@ already_AddRefed<imgRequestProxy> ImageLoader::LoadImage(
if (NS_FAILED(rv) || !request) { if (NS_FAILED(rv) || !request) {
return nullptr; return nullptr;
} }
sImages->LookupOrInsertWith(request, sImages->GetOrInsertNew(request);
[] { return MakeUnique<ImageTableEntry>(); });
return request.forget(); return request.forget();
} }

View File

@ -106,9 +106,7 @@ ShadowParts ShadowParts::Parse(const nsAString& aString) {
continue; continue;
} }
nsAtom* second = mapping.second.get(); nsAtom* second = mapping.second.get();
parts.mMappings parts.mMappings.GetOrInsertNew(mapping.first)
.LookupOrInsertWith(mapping.first,
[] { return MakeUnique<PartList>(); })
->AppendElement(std::move(mapping.second)); ->AppendElement(std::move(mapping.second));
parts.mReverseMappings.InsertOrUpdate(second, std::move(mapping.first)); parts.mReverseMappings.InsertOrUpdate(second, std::move(mapping.first));
} }

View File

@ -2195,9 +2195,7 @@ void CacheFile::QueueChunkListener(uint32_t aIndex,
} }
item->mCallback = aCallback; item->mCallback = aCallback;
mChunkListeners mChunkListeners.GetOrInsertNew(aIndex)->mItems.AppendElement(item);
.LookupOrInsertWith(aIndex, [] { return MakeUnique<ChunkListeners>(); })
->mItems.AppendElement(item);
} }
nsresult CacheFile::NotifyChunkListeners(uint32_t aIndex, nsresult aResult, nsresult CacheFile::NotifyChunkListeners(uint32_t aIndex, nsresult aResult,

View File

@ -135,11 +135,7 @@ nsresult ChildDNSService::AsyncResolveInternal(
nsCString key; nsCString key;
GetDNSRecordHashKey(hostname, DNSResolverInfo::URL(aResolver), type, GetDNSRecordHashKey(hostname, DNSResolverInfo::URL(aResolver), type,
aOriginAttributes, flags, originalListenerAddr, key); aOriginAttributes, flags, originalListenerAddr, key);
mPendingRequests mPendingRequests.GetOrInsertNew(key)->AppendElement(sender);
.LookupOrInsertWith(
key,
[] { return MakeUnique<nsTArray<RefPtr<DNSRequestSender>>>(); })
->AppendElement(sender);
} }
sender->StartRequest(); sender->StartRequest();

View File

@ -860,8 +860,7 @@ nsresult DNSPacket::DecodeInternal(
auto parseRecord = [&]() { auto parseRecord = [&]() {
LOG(("Parsing additional record type: %u", type)); LOG(("Parsing additional record type: %u", type));
auto& entry = aAdditionalRecords.LookupOrInsertWith( auto* entry = aAdditionalRecords.GetOrInsertNew(qname);
qname, [] { return MakeUnique<DOHresp>(); });
switch (type) { switch (type) {
case TRRTYPE_A: case TRRTYPE_A:

View File

@ -1434,9 +1434,7 @@ nsDNSService::ReportFailedSVCDomainName(const nsACString& aOwnerName,
const nsACString& aSVCDomainName) { const nsACString& aSVCDomainName) {
MutexAutoLock lock(mLock); MutexAutoLock lock(mLock);
mFailedSVCDomainNames mFailedSVCDomainNames.GetOrInsertNew(aOwnerName, 1)
.LookupOrInsertWith(aOwnerName,
[] { return MakeUnique<nsTArray<nsCString>>(1); })
->AppendElement(aSVCDomainName); ->AppendElement(aSVCDomainName);
return NS_OK; return NS_OK;
} }

View File

@ -57,14 +57,11 @@ void PendingTransactionQueue::InsertTransactionNormal(
uint64_t windowId = TabIdForQueuing(info->Transaction()); uint64_t windowId = TabIdForQueuing(info->Transaction());
nsTArray<RefPtr<PendingTransactionInfo>>* const infoArray = nsTArray<RefPtr<PendingTransactionInfo>>* const infoArray =
mPendingTransactionTable mPendingTransactionTable.GetOrInsertNew(windowId);
.LookupOrInsertWith(
windowId,
[] {
return MakeUnique<nsTArray<RefPtr<PendingTransactionInfo>>>();
})
.get();
// XXX At least if a new array was empty before, this isn't efficient, as it
// does an insert-sort. It would be better to just append all elements and
// then sort.
InsertTransactionSorted(*infoArray, info, aInsertAsFirstForTheSamePriority); InsertTransactionSorted(*infoArray, info, aInsertAsFirstForTheSamePriority);
} }

View File

@ -3344,11 +3344,8 @@ void nsHttpConnectionMgr::RegisterOriginCoalescingKey(HttpConnectionBase* conn,
nsCString newKey; nsCString newKey;
BuildOriginFrameHashKey(newKey, ci, host, port); BuildOriginFrameHashKey(newKey, ci, host, port);
mCoalescingHash mCoalescingHash.GetOrInsertNew(newKey, 1)->AppendElement(
.LookupOrInsertWith(newKey, do_GetWeakReference(static_cast<nsISupportsWeakReference*>(conn)));
[] { return MakeUnique<nsTArray<nsWeakPtr>>(1); })
->AppendElement(
do_GetWeakReference(static_cast<nsISupportsWeakReference*>(conn)));
LOG( LOG(
("nsHttpConnectionMgr::RegisterOriginCoalescingKey " ("nsHttpConnectionMgr::RegisterOriginCoalescingKey "

View File

@ -119,14 +119,9 @@ nsresult nsStreamConverterService::AddAdjacency(const char* aContractID) {
// each MIME-type is represented as a key in our hashtable. // each MIME-type is represented as a key in our hashtable.
nsTArray<RefPtr<nsAtom>>* const fromEdges = nsTArray<RefPtr<nsAtom>>* const fromEdges =
mAdjacencyList mAdjacencyList.GetOrInsertNew(fromStr);
.LookupOrInsertWith(
fromStr,
[] { return mozilla::MakeUnique<nsTArray<RefPtr<nsAtom>>>(); })
.get();
mozilla::Unused << mAdjacencyList.LookupOrInsertWith( mAdjacencyList.GetOrInsertNew(toStr);
toStr, [] { return mozilla::MakeUnique<nsTArray<RefPtr<nsAtom>>>(); });
// Now we know the FROM and TO types are represented as keys in the hashtable. // Now we know the FROM and TO types are represented as keys in the hashtable.
// Let's "connect" the verticies, making an edge. // Let's "connect" the verticies, making an edge.

View File

@ -1098,10 +1098,7 @@ void NativeFileWatcherIOTask::AppendCallbacksToHashtables(
const nsMainThreadPtrHandle<nsINativeFileWatcherErrorCallback>& const nsMainThreadPtrHandle<nsINativeFileWatcherErrorCallback>&
aOnErrorHandle) { aOnErrorHandle) {
ChangeCallbackArray* const callbacksArray = ChangeCallbackArray* const callbacksArray =
mChangeCallbacksTable mChangeCallbacksTable.GetOrInsertNew(aPath);
.LookupOrInsertWith(aPath,
[] { return MakeUnique<ChangeCallbackArray>(); })
.get();
// Now we do have an entry for that path. Check to see if the callback is // Now we do have an entry for that path. Check to see if the callback is
// already there. // already there.
@ -1115,10 +1112,7 @@ void NativeFileWatcherIOTask::AppendCallbacksToHashtables(
// Same thing for the error callback. // Same thing for the error callback.
ErrorCallbackArray* const errorCallbacksArray = ErrorCallbackArray* const errorCallbacksArray =
mErrorCallbacksTable mErrorCallbacksTable.GetOrInsertNew(aPath);
.LookupOrInsertWith(aPath,
[] { return MakeUnique<ErrorCallbackArray>(); })
.get();
ErrorCallbackArray::index_type errorCallbackIndex = ErrorCallbackArray::index_type errorCallbackIndex =
errorCallbacksArray->IndexOf(aOnErrorHandle); errorCallbacksArray->IndexOf(aOnErrorHandle);

View File

@ -375,10 +375,7 @@ bool IsExpired(const EventKey& key) { return key.id == kExpiredEventId; }
EventRecordArray* GetEventRecordsForProcess(const StaticMutexAutoLock& lock, EventRecordArray* GetEventRecordsForProcess(const StaticMutexAutoLock& lock,
ProcessID processType) { ProcessID processType) {
return gEventRecords return gEventRecords.GetOrInsertNew(uint32_t(processType));
.LookupOrInsertWith(uint32_t(processType),
[] { return MakeUnique<EventRecordArray>(); })
.get();
} }
EventKey* GetEventKey(const StaticMutexAutoLock& lock, EventKey* GetEventKey(const StaticMutexAutoLock& lock,

View File

@ -1514,10 +1514,7 @@ nsresult internal_GetScalarByEnum(const StaticMutexAutoLock& lock,
// Get the process-specific storage or create one if it's not // Get the process-specific storage or create one if it's not
// available. // available.
ScalarStorageMapType* const scalarStorage = ScalarStorageMapType* const scalarStorage =
processStorage processStorage.GetOrInsertNew(storageId);
.LookupOrInsertWith(storageId,
[] { return MakeUnique<ScalarStorageMapType>(); })
.get();
// Check if the scalar is already allocated in the parent or in the child // Check if the scalar is already allocated in the parent or in the child
// storage. // storage.
@ -1798,10 +1795,7 @@ nsresult internal_GetKeyedScalarByEnum(const StaticMutexAutoLock& lock,
// Get the process-specific storage or create one if it's not // Get the process-specific storage or create one if it's not
// available. // available.
KeyedScalarStorageMapType* const scalarStorage = KeyedScalarStorageMapType* const scalarStorage =
processStorage processStorage.GetOrInsertNew(storageId);
.LookupOrInsertWith(
storageId, [] { return MakeUnique<KeyedScalarStorageMapType>(); })
.get();
if (scalarStorage->Get(aId.id, &scalar)) { if (scalarStorage->Get(aId.id, &scalar)) {
*aRet = scalar; *aRet = scalar;

View File

@ -868,11 +868,7 @@ nsresult EventDispatcher::IterateEvents(JSContext* aCx, JS::HandleValue aEvents,
nsresult EventDispatcher::RegisterEventLocked( nsresult EventDispatcher::RegisterEventLocked(
const nsAString& aEvent, nsIAndroidEventListener* aListener) { const nsAString& aEvent, nsIAndroidEventListener* aListener) {
ListenersList* list = ListenersList* list = mListenersMap.GetOrInsertNew(aEvent);
mListenersMap
.LookupOrInsertWith(aEvent,
[] { return MakeUnique<ListenersList>(); })
.get();
#ifdef DEBUG #ifdef DEBUG
for (ssize_t i = 0; i < list->listeners.Count(); i++) { for (ssize_t i = 0; i < list->listeners.Count(); i++) {

View File

@ -483,11 +483,7 @@ nsresult WakeLockListener::Callback(const nsAString& topic,
return NS_OK; return NS_OK;
WakeLockTopic* const topicLock = WakeLockTopic* const topicLock =
mTopics mTopics.GetOrInsertNew(topic, topic, mConnection);
.LookupOrInsertWith(
topic,
[&] { return MakeUnique<WakeLockTopic>(topic, mConnection); })
.get();
// Treat "locked-background" the same as "unlocked" on desktop linux. // Treat "locked-background" the same as "unlocked" on desktop linux.
bool shouldLock = state.EqualsLiteral("locked-foreground"); bool shouldLock = state.EqualsLiteral("locked-foreground");

View File

@ -726,10 +726,7 @@ void nsComponentManagerImpl::ManifestComponent(ManifestProcessingContext& aCx,
return; return;
} }
KnownModule* const km = KnownModule* const km = mKnownModules.GetOrInsertNew(hash, fl);
mKnownModules
.LookupOrInsertWith(hash, [&] { return MakeUnique<KnownModule>(fl); })
.get();
void* place = mArena.Allocate(sizeof(nsCID)); void* place = mArena.Allocate(sizeof(nsCID));
nsID* permanentCID = static_cast<nsID*>(place); nsID* permanentCID = static_cast<nsID*>(place);