Skip to content

Commit

Permalink
Bug 1691913 - Rename nsBaseHashtable::GetOrInsert(With) to LookupOrIn…
Browse files Browse the repository at this point in the history
…sert(With). r=xpcom-reviewers,necko-reviewers,jgilbert,dragana,nika

The functions should be called "Lookup" rather than "Get" because they return
a DataType& (rather than UserDataType).

Differential Revision: https://phabricator.services.mozilla.com/D105472
  • Loading branch information
sigiesec committed Feb 26, 2021
1 parent d57c853 commit 4f75368
Show file tree
Hide file tree
Showing 83 changed files with 225 additions and 211 deletions.
2 changes: 1 addition & 1 deletion accessible/base/NotificationController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -532,7 +532,7 @@ void NotificationController::ProcessMutationEvents() {
}

LocalAccessible* parent = event->GetAccessible()->LocalParent();
showEvents.GetOrInsert(parent).AppendElement(event);
showEvents.LookupOrInsert(parent).AppendElement(event);
}

// We need to fire show events for the children of an accessible in the order
Expand Down
7 changes: 4 additions & 3 deletions accessible/generic/DocAccessible-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -165,12 +165,13 @@ inline DocAccessible::AttrRelProviders* DocAccessible::GetOrCreateRelProviders(
aElement->GetUncomposedDocOrConnectedShadowRoot();
DependentIDsHashtable* hash =
mDependentIDsHashes
.GetOrInsertWith(docOrShadowRoot,
[] { return MakeUnique<DependentIDsHashtable>(); })
.LookupOrInsertWith(
docOrShadowRoot,
[] { return MakeUnique<DependentIDsHashtable>(); })
.get();

return hash
->GetOrInsertWith(aID, [] { return MakeUnique<AttrRelProviders>(); })
->LookupOrInsertWith(aID, [] { return MakeUnique<AttrRelProviders>(); })
.get();
}

Expand Down
7 changes: 4 additions & 3 deletions docshell/base/BrowsingContextGroup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,9 @@ already_AddRefed<BrowsingContextGroup> BrowsingContextGroup::GetOrCreate(
ClearOnShutdown(&sBrowsingContextGroups);
}

RefPtr<BrowsingContextGroup> group = sBrowsingContextGroups->GetOrInsertWith(
aId, [&aId] { return do_AddRef(new BrowsingContextGroup(aId)); });
RefPtr<BrowsingContextGroup> group =
sBrowsingContextGroups->LookupOrInsertWith(
aId, [&aId] { return do_AddRef(new BrowsingContextGroup(aId)); });
return group.forget();
}

Expand Down Expand Up @@ -403,7 +404,7 @@ already_AddRefed<DocGroup> BrowsingContextGroup::AddDocument(
const nsACString& aKey, Document* aDocument) {
MOZ_ASSERT(NS_IsMainThread());

RefPtr<DocGroup>& docGroup = mDocGroups.GetOrInsertWith(
RefPtr<DocGroup>& docGroup = mDocGroups.LookupOrInsertWith(
aKey, [&] { return DocGroup::Create(this, aKey); });

docGroup->AddDocument(aDocument);
Expand Down
2 changes: 1 addition & 1 deletion docshell/base/WindowContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ void WindowContext::Init() {
gWindowContexts = new WindowContextByIdMap();
ClearOnShutdown(&gWindowContexts);
}
auto& entry = gWindowContexts->GetOrInsert(mInnerWindowId);
auto& entry = gWindowContexts->LookupOrInsert(mInnerWindowId);
MOZ_RELEASE_ASSERT(!entry, "Duplicate WindowContext for ID!");
entry = this;

Expand Down
2 changes: 1 addition & 1 deletion dom/animation/EffectCompositor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ void EffectCompositor::RequestRestyle(dom::Element* aElement,
auto& elementsToRestyle = mElementsToRestyle[aCascadeLevel];
PseudoElementHashEntry::KeyType key = {aElement, aPseudoType};

bool& restyleEntry = elementsToRestyle.GetOrInsert(key, false);
bool& restyleEntry = elementsToRestyle.LookupOrInsert(key, false);
if (aRestyleType == RestyleType::Throttled) {
mPresContext->PresShell()->SetNeedThrottledAnimationFlush();
} else {
Expand Down
2 changes: 1 addition & 1 deletion dom/base/Document.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -812,7 +812,7 @@ Document* ExternalResourceMap::RequestResource(
return resource->mDocument;
}

RefPtr<PendingLoad>& loadEntry = mPendingLoads.GetOrInsert(clone);
RefPtr<PendingLoad>& loadEntry = mPendingLoads.LookupOrInsert(clone);
if (loadEntry) {
RefPtr<PendingLoad> load(loadEntry);
load.forget(aPendingLoad);
Expand Down
2 changes: 1 addition & 1 deletion dom/base/Document.h
Original file line number Diff line number Diff line change
Expand Up @@ -1635,7 +1635,7 @@ class Document : public nsINode,
RawServoSelectorList* GetListOrInsertFrom(const nsACString& aSelector,
F&& aFrom) {
MOZ_ASSERT(NS_IsMainThread());
return mTable.GetOrInsertWith(aSelector, std::forward<F>(aFrom)).get();
return mTable.LookupOrInsertWith(aSelector, std::forward<F>(aFrom)).get();
}

~SelectorCache();
Expand Down
5 changes: 3 additions & 2 deletions dom/base/DocumentOrShadowRoot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ void DocumentOrShadowRoot::CloneAdoptedSheetsFrom(
MOZ_ASSERT(clonedSheetMap);

for (const StyleSheet* sheet : aSource.mAdoptedStyleSheets) {
RefPtr<StyleSheet> clone = clonedSheetMap->GetOrInsertWith(
RefPtr<StyleSheet> clone = clonedSheetMap->LookupOrInsertWith(
sheet, [&] { return sheet->CloneAdoptedSheet(ownerDoc); });
MOZ_ASSERT(clone);
MOZ_DIAGNOSTIC_ASSERT(clone->ConstructorDocumentMatches(ownerDoc));
Expand Down Expand Up @@ -753,7 +753,8 @@ nsRadioGroupStruct* DocumentOrShadowRoot::GetRadioGroup(
nsRadioGroupStruct* DocumentOrShadowRoot::GetOrCreateRadioGroup(
const nsAString& aName) {
return mRadioGroups
.GetOrInsertWith(aName, [] { return MakeUnique<nsRadioGroupStruct>(); })
.LookupOrInsertWith(aName,
[] { return MakeUnique<nsRadioGroupStruct>(); })
.get();
}

Expand Down
2 changes: 1 addition & 1 deletion dom/base/Element.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3959,7 +3959,7 @@ void Element::RegisterIntersectionObserver(DOMIntersectionObserver* aObserver) {
// notification task being scheduled.
// -1: Non-intersecting.
// >= 0: Intersecting, valid index of aObserver->mThresholds.
Unused << observers->GetOrInsert(aObserver, eUninitialized);
observers->LookupOrInsert(aObserver, eUninitialized);
}

void Element::UnregisterIntersectionObserver(
Expand Down
4 changes: 2 additions & 2 deletions dom/base/EventSourceEventService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,8 +203,8 @@ EventSourceEventService::AddListener(uint64_t aInnerWindowID,

WindowListener* listener =
mWindows
.GetOrInsertWith(aInnerWindowID,
[] { return MakeUnique<WindowListener>(); })
.LookupOrInsertWith(aInnerWindowID,
[] { return MakeUnique<WindowListener>(); })
.get();

listener->mListeners.AppendElement(aListener);
Expand Down
2 changes: 1 addition & 1 deletion dom/base/ResizeObserver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ void ResizeObserver::Observe(Element& aTarget,
mDocument->AddResizeObserver(*this);
}

auto& observation = mObservationMap.GetOrInsert(&aTarget);
auto& observation = mObservationMap.LookupOrInsert(&aTarget);
if (observation) {
if (observation->BoxOptions() == aOptions.mBox) {
// Already observed this target and the observed box is the same, so
Expand Down
2 changes: 1 addition & 1 deletion dom/base/nsDOMAttributeMap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ Attr* nsDOMAttributeMap::GetAttribute(mozilla::dom::NodeInfo* aNodeInfo) {

nsAttrKey attr(aNodeInfo->NamespaceID(), aNodeInfo->NameAtom());

return mAttributeCache.GetOrInsertWith(attr, [&] {
return mAttributeCache.LookupOrInsertWith(attr, [&] {
// Newly inserted entry!
RefPtr<mozilla::dom::NodeInfo> ni = aNodeInfo;
auto* nim = ni->NodeInfoManager();
Expand Down
4 changes: 2 additions & 2 deletions dom/base/nsDOMMutationObserver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ void nsMutationReceiver::ContentRemoved(nsIContent* aChild,
auto* const transientReceivers =
Observer()
->mTransientReceivers
.GetOrInsertWith(
.LookupOrInsertWith(
aChild,
[&isNewEntry] {
isNewEntry = true;
Expand Down Expand Up @@ -1040,7 +1040,7 @@ void nsAutoMutationBatch::Done() {
if (allObservers.Length()) {
auto* const transientReceivers =
ob->mTransientReceivers
.GetOrInsertWith(
.LookupOrInsertWith(
removed,
[] { return MakeUnique<nsCOMArray<nsMutationReceiver>>(); })
.get();
Expand Down
4 changes: 2 additions & 2 deletions dom/base/nsFrameMessageManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ void nsFrameMessageManager::AddMessageListener(const nsAString& aMessageName,
ErrorResult& aError) {
auto* const listeners =
mListeners
.GetOrInsertWith(
.LookupOrInsertWith(
aMessageName,
[] {
return MakeUnique<
Expand Down Expand Up @@ -316,7 +316,7 @@ void nsFrameMessageManager::AddWeakMessageListener(

auto* const listeners =
mListeners
.GetOrInsertWith(
.LookupOrInsertWith(
aMessageName,
[] {
return MakeUnique<
Expand Down
2 changes: 1 addition & 1 deletion dom/base/nsGlobalWindowInner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7161,7 +7161,7 @@ ChromeMessageBroadcaster* nsGlobalWindowInner::GetGroupMessageManager(
MOZ_ASSERT(IsChromeWindow());

return mChromeFields.mGroupMessageManagers
.GetOrInsertWith(
.LookupOrInsertWith(
aGroup,
[&] {
return MakeAndAddRef<ChromeMessageBroadcaster>(MessageManager());
Expand Down
2 changes: 1 addition & 1 deletion dom/broadcastchannel/BroadcastChannelService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ void BroadcastChannelService::RegisterActor(

auto* const parents =
mAgents
.GetOrInsertWith(
.LookupOrInsertWith(
aOriginChannelKey,
[] { return MakeUnique<nsTArray<BroadcastChannelParent*>>(); })
.get();
Expand Down
2 changes: 1 addition & 1 deletion dom/clients/manager/ClientManagerService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ ClientSourceParent* ClientManagerService::FindSource(

void ClientManagerService::WaitForSource(ClientHandleParent* aHandle,
const nsID& aID) {
auto& entry = mPendingHandles.GetOrInsert(aID);
auto& entry = mPendingHandles.LookupOrInsert(aID);
entry.AppendElement(aHandle);
}

Expand Down
5 changes: 3 additions & 2 deletions dom/commandhandler/nsCommandManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,9 @@ nsCommandManager::AddCommandObserver(nsIObserver* aCommandObserver,
// for each command in the table, we make a list of observers for that command
auto* const commandObservers =
mObserversTable
.GetOrInsertWith(aCommandToObserve,
[] { return mozilla::MakeUnique<ObserverList>(); })
.LookupOrInsertWith(
aCommandToObserve,
[] { return mozilla::MakeUnique<ObserverList>(); })
.get();

// need to check that this command observer hasn't already been registered
Expand Down
2 changes: 1 addition & 1 deletion dom/events/EventListenerService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ void EventListenerService::NotifyAboutMainThreadListenerChangeInternal(
}

RefPtr<EventListenerChange> changes =
mPendingListenerChangesSet.GetOrInsertWith(aTarget, [&] {
mPendingListenerChangesSet.LookupOrInsertWith(aTarget, [&] {
auto c = MakeRefPtr<EventListenerChange>(aTarget);
mPendingListenerChanges->AppendElement(c);
return c;
Expand Down
4 changes: 2 additions & 2 deletions dom/events/EventStateManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4690,8 +4690,8 @@ OverOutElementsWrapper* EventStateManager::GetWrapperByEventID(
return mMouseEnterLeaveHelper;
}
return mPointersEnterLeaveHelper
.GetOrInsertWith(pointer->pointerId,
[] { return new OverOutElementsWrapper(); })
.LookupOrInsertWith(pointer->pointerId,
[] { return new OverOutElementsWrapper(); })
.get();
}

Expand Down
2 changes: 1 addition & 1 deletion dom/filehandle/ActorsParent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -674,7 +674,7 @@ void FileHandleThreadPool::Enqueue(FileHandle* aFileHandle,

DirectoryInfo* directoryInfo =
mDirectoryInfos
.GetOrInsertWith(
.LookupOrInsertWith(
directoryId,
[&] { return UniquePtr<DirectoryInfo>(new DirectoryInfo(this)); })
.get();
Expand Down
13 changes: 7 additions & 6 deletions dom/html/HTMLAllCollection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,13 @@ static bool DocAllResultMatch(Element* aElement, int32_t aNamespaceID,

nsContentList* HTMLAllCollection::GetDocumentAllList(const nsAString& aID) {
return mNamedMap
.GetOrInsertWith(aID,
[this, &aID] {
RefPtr<nsAtom> id = NS_Atomize(aID);
return new nsContentList(mDocument, DocAllResultMatch,
nullptr, nullptr, true, id);
})
.LookupOrInsertWith(aID,
[this, &aID] {
RefPtr<nsAtom> id = NS_Atomize(aID);
return new nsContentList(mDocument,
DocAllResultMatch, nullptr,
nullptr, true, id);
})
.get();
}

Expand Down
2 changes: 1 addition & 1 deletion dom/html/HTMLFormElement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2147,7 +2147,7 @@ HTMLFormElement::WalkRadioGroup(const nsAString& aName,
void HTMLFormElement::AddToRadioGroup(const nsAString& aName,
HTMLInputElement* aRadio) {
if (aRadio->IsRequired()) {
uint32_t& value = mRequiredRadioButtonCounts.GetOrInsert(aName, 0);
uint32_t& value = mRequiredRadioButtonCounts.LookupOrInsert(aName, 0);
++value;
}
}
Expand Down
12 changes: 6 additions & 6 deletions dom/indexedDB/ActorsParent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7628,11 +7628,11 @@ nsresult DatabaseConnection::UpdateRefcountFunction::ProcessValue(

const auto entry =
WrapNotNull(mFileInfoEntries
.GetOrInsertWith(id,
[&file] {
return MakeUnique<FileInfoEntry>(
file.FileInfoPtr());
})
.LookupOrInsertWith(id,
[&file] {
return MakeUnique<FileInfoEntry>(
file.FileInfoPtr());
})
.get());

if (mInSavepoint) {
Expand Down Expand Up @@ -16776,7 +16776,7 @@ void OpenDatabaseOp::EnsureDatabaseActor() {
info->mLiveDatabases.AppendElement(
WrapNotNullUnchecked(mDatabase.unsafeGetRawPtr()));
} else {
// XXX Maybe use GetOrInsertWith above, to avoid a second lookup here?
// XXX Maybe use LookupOrInsertWith above, to avoid a second lookup here?
info = gLiveDatabaseHashtable
->Put(mDatabaseId,
MakeUnique<DatabaseActorInfo>(
Expand Down
2 changes: 1 addition & 1 deletion dom/ipc/WindowGlobalParent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ void WindowGlobalParent::OriginCounter::UpdateSiteOriginsFrom(
aParent->DocumentPrincipal()->GetSiteOrigin(origin);

if (aIncrease) {
int32_t& count = mOriginMap.GetOrInsert(origin);
int32_t& count = mOriginMap.LookupOrInsert(origin);
count += 1;
mMaxOrigins = std::max(mMaxOrigins, mOriginMap.Count());
} else if (auto entry = mOriginMap.Lookup(origin)) {
Expand Down
4 changes: 2 additions & 2 deletions dom/localstorage/ActorsParent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3228,7 +3228,7 @@ bool RecvPBackgroundLSObserverConstructor(PBackgroundLSObserverParent* aActor,

nsTArray<NotNull<Observer*>>* const array =
gObservers
->GetOrInsertWith(
->LookupOrInsertWith(
notNullObserver->Origin(),
[] { return MakeUnique<nsTArray<NotNull<Observer*>>>(); })
.get();
Expand Down Expand Up @@ -5451,7 +5451,7 @@ void Snapshot::SaveItem(const nsAString& aKey, const LSValue& aOldValue,
}

if (!mLoadedItems.GetEntry(aKey) && !mUnknownItems.GetEntry(aKey)) {
Unused << mValues.GetOrInsert(aKey, aOldValue);
mValues.LookupOrInsert(aKey, aOldValue);
}

if (aAffectsOrder && !mSavedKeys) {
Expand Down
2 changes: 1 addition & 1 deletion dom/media/MediaManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2793,7 +2793,7 @@ RefPtr<MediaManager::StreamPromise> MediaManager::GetUserMedia(
// things down
nsTArray<nsString>* const array =
self->mCallIds
.GetOrInsertWith(
.LookupOrInsertWith(
windowID,
[] { return MakeUnique<nsTArray<nsString>>(); })
.get();
Expand Down
2 changes: 1 addition & 1 deletion dom/media/MediaTrackGraph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -634,7 +634,7 @@ void MediaTrackGraphImpl::OpenAudioInputImpl(CubebUtils::AudioDeviceID aID,
// Only allow one device per MTG (hence, per document), but allow opening a
// device multiple times
nsTArray<RefPtr<AudioDataListener>>& listeners =
mInputDeviceUsers.GetOrInsert(aID);
mInputDeviceUsers.LookupOrInsert(aID);
if (listeners.IsEmpty() && mInputDeviceUsers.Count() > 1) {
// We don't support opening multiple input device in a graph for now.
listeners.RemoveElement(aID);
Expand Down
8 changes: 4 additions & 4 deletions dom/media/gmp/GMPMemoryStorage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ class GMPMemoryStorage : public GMPStorage {
GMPErr Open(const nsCString& aRecordName) override {
MOZ_ASSERT(!IsOpen(aRecordName));

Record* record =
mRecords
.GetOrInsertWith(aRecordName, [] { return MakeUnique<Record>(); })
.get();
Record* record = mRecords
.LookupOrInsertWith(
aRecordName, [] { return MakeUnique<Record>(); })
.get();
record->mIsOpen = true;
return GMPNoErr;
}
Expand Down
2 changes: 1 addition & 1 deletion dom/media/ogg/OggCodecState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1712,7 +1712,7 @@ bool SkeletonState::DecodeFisbone(ogg_packet* aPacket) {

if ((i == 0 && IsAscii(strMsg)) || (i != 0 && IsUtf8(strMsg))) {
EMsgHeaderType eHeaderType = kFieldTypeMaps[i].mMsgHeaderType;
Unused << field->mValuesStore.GetOrInsertWith(
Unused << field->mValuesStore.LookupOrInsertWith(
eHeaderType, [i, msgHead, msgProbe]() {
uint32_t nameLen =
strlen(kFieldTypeMaps[i].mPatternToRecognize);
Expand Down
2 changes: 1 addition & 1 deletion dom/payments/PaymentRequestManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ nsresult PaymentRequestManager::SendRequestPayment(
}

if (aResponseExpected) {
++mActivePayments.GetOrInsert(aRequest, 0);
++mActivePayments.LookupOrInsert(aRequest, 0);
}
return NS_OK;
}
Expand Down
Loading

0 comments on commit 4f75368

Please sign in to comment.