Skip to content

Commit

Permalink
Bug 1184468 - Use nsBaseHashtable::Values. r=xpcom-reviewers,nika
Browse files Browse the repository at this point in the history
  • Loading branch information
sigiesec committed Mar 24, 2021
1 parent 8077676 commit 5f56a5e
Show file tree
Hide file tree
Showing 112 changed files with 447 additions and 627 deletions.
3 changes: 1 addition & 2 deletions accessible/base/DocManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,7 @@ DocAccessible* DocManager::GetDocAccessible(const PresShell* aPresShell) {
}

LocalAccessible* DocManager::FindAccessibleInCache(nsINode* aNode) const {
for (const auto& entry : mDocAccessibleCache) {
DocAccessible* docAccessible = entry.GetData().get();
for (const auto& docAccessible : mDocAccessibleCache.Values()) {
NS_ASSERTION(docAccessible,
"No doc accessible for the object in doc accessible cache!");

Expand Down
3 changes: 1 addition & 2 deletions accessible/generic/ApplicationAccessible.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,7 @@ void ApplicationAccessible::Init() {
return;
}

for (const auto& entry : *windowsById) {
nsGlobalWindowOuter* window = entry.GetData();
for (const auto& window : windowsById->Values()) {
if (window->GetDocShell() && window->IsRootOuterWindow()) {
if (RefPtr<dom::Document> docNode = window->GetExtantDoc()) {
GetAccService()->GetDocAccessible(docNode); // ensure creation
Expand Down
8 changes: 3 additions & 5 deletions accessible/generic/DocAccessible.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,8 @@ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(DocAccessible,
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mNotificationController)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mVirtualCursor)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mChildDocuments)
for (const auto& hashEntry : tmp->mDependentIDsHashes) {
for (const auto& providerEntry : *hashEntry.GetData()) {
AttrRelProviders* providers = providerEntry.GetData().get();
for (const auto& hashEntry : tmp->mDependentIDsHashes.Values()) {
for (const auto& providers : hashEntry->Values()) {
for (int32_t provIdx = providers->Length() - 1; provIdx >= 0; provIdx--) {
NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(
cb, "content of dependent ids hash entry of document accessible");
Expand All @@ -130,8 +129,7 @@ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(DocAccessible,
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mAccessibleCache)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mAnchorJumpElm)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mInvalidationList)
for (const auto& arEntry : tmp->mARIAOwnsHash) {
nsTArray<RefPtr<LocalAccessible>>* ar = arEntry.GetData().get();
for (const auto& ar : tmp->mARIAOwnsHash.Values()) {
for (uint32_t i = 0; i < ar->Length(); i++) {
NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(cb, "mARIAOwnsHash entry item");
cb.NoteXPCOMChild(ar->ElementAt(i));
Expand Down
8 changes: 4 additions & 4 deletions docshell/base/BrowsingContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1333,8 +1333,8 @@ void BrowsingContext::DiscardFromContentParent(ContentParent* aCP) {

if (sBrowsingContexts) {
AutoTArray<RefPtr<BrowsingContext>, 8> toDiscard;
for (const auto& entry : *sBrowsingContexts) {
auto* bc = entry.GetData()->Canonical();
for (const auto& data : sBrowsingContexts->Values()) {
auto* bc = data->Canonical();
if (!bc->IsDiscarded() && bc->IsEmbeddedInProcess(aCP->ChildID())) {
toDiscard.AppendElement(bc);
}
Expand Down Expand Up @@ -2693,8 +2693,8 @@ bool BrowsingContext::LegacyCheckOnlyOwningProcessCanSet(
return true;
}

auto BrowsingContext::LegacyRevertIfNotOwningOrParentProcess(ContentParent* aSource)
-> CanSetResult {
auto BrowsingContext::LegacyRevertIfNotOwningOrParentProcess(
ContentParent* aSource) -> CanSetResult {
if (aSource) {
MOZ_ASSERT(XRE_IsParentProcess());

Expand Down
13 changes: 4 additions & 9 deletions docshell/base/BrowsingContextGroup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -234,8 +234,8 @@ void BrowsingContextGroup::Destroy() {
// Make sure to call `RemoveBrowsingContextGroup` for every entry in both
// `mHosts` and `mSubscribers`. This will visit most entries twice, but
// `RemoveBrowsingContextGroup` is safe to call multiple times.
for (auto& entry : mHosts) {
entry.GetData()->RemoveBrowsingContextGroup(this);
for (auto& entry : mHosts.Values()) {
entry->RemoveBrowsingContextGroup(this);
}
for (auto& entry : mSubscribers) {
entry.GetKey()->RemoveBrowsingContextGroup(this);
Expand Down Expand Up @@ -395,9 +395,7 @@ BrowsingContextGroup* BrowsingContextGroup::GetChromeGroup() {

void BrowsingContextGroup::GetDocGroups(nsTArray<DocGroup*>& aDocGroups) {
MOZ_ASSERT(NS_IsMainThread());
for (const auto& entry : mDocGroups) {
aDocGroups.AppendElement(entry.GetData());
}
AppendToArray(aDocGroups, mDocGroups.Values());
}

already_AddRefed<DocGroup> BrowsingContextGroup::AddDocument(
Expand Down Expand Up @@ -443,10 +441,7 @@ void BrowsingContextGroup::GetAllGroups(
return;
}

aGroups.SetCapacity(sBrowsingContextGroups->Count());
for (auto& group : *sBrowsingContextGroups) {
aGroups.AppendElement(group.GetData());
}
aGroups = ToArray(sBrowsingContextGroups->Values());
}

NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(BrowsingContextGroup, mContexts,
Expand Down
4 changes: 2 additions & 2 deletions docshell/base/ChildProcessChannelListener.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ void ChildProcessChannelListener::OnChannelReady(
}

ChildProcessChannelListener::~ChildProcessChannelListener() {
for (auto& args : mChannelArgs) {
args.GetData().mResolver(NS_ERROR_FAILURE);
for (const auto& args : mChannelArgs.Values()) {
args.mResolver(NS_ERROR_FAILURE);
}
}

Expand Down
4 changes: 2 additions & 2 deletions dom/base/CustomElementRegistry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1284,8 +1284,8 @@ already_AddRefed<nsISupports> CustomElementRegistry::CallGetCustomInterface(
}

void CustomElementRegistry::TraceDefinitions(JSTracer* aTrc) {
for (const auto& entry : mCustomDefinitions) {
const RefPtr<CustomElementDefinition>& definition = entry.GetData();
for (const RefPtr<CustomElementDefinition>& definition :
mCustomDefinitions.Values()) {
if (definition && definition->mConstructor) {
mozilla::TraceScriptHolder(definition->mConstructor, aTrc);
}
Expand Down
4 changes: 2 additions & 2 deletions dom/base/Document.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -842,8 +842,8 @@ Document* ExternalResourceMap::RequestResource(

void ExternalResourceMap::EnumerateResources(SubDocEnumFunc aCallback) {
nsTArray<RefPtr<Document>> docs(mMap.Count());
for (const auto& entry : mMap) {
if (Document* doc = entry.GetData()->mDocument) {
for (const auto& entry : mMap.Values()) {
if (Document* doc = entry->mDocument) {
docs.AppendElement(doc);
}
}
Expand Down
3 changes: 1 addition & 2 deletions dom/base/nsCCUncollectableMarker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -459,8 +459,7 @@ void mozilla::dom::TraceBlackJS(JSTracer* aTrc, bool aIsShutdownGC) {
nsGlobalWindowOuter::OuterWindowByIdTable* windowsById =
nsGlobalWindowOuter::GetWindowsTable();
if (windowsById) {
for (const auto& entry : *windowsById) {
nsGlobalWindowOuter* window = entry.GetData();
for (nsGlobalWindowOuter* window : windowsById->Values()) {
if (!window->IsCleanedUp()) {
nsGlobalWindowInner* inner = nullptr;
for (PRCList* win = PR_LIST_HEAD(window); win != window;
Expand Down
4 changes: 2 additions & 2 deletions dom/base/nsDOMAttributeMap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,8 @@ NS_IMPL_CYCLE_COLLECTING_ADDREF(nsDOMAttributeMap)
NS_IMPL_CYCLE_COLLECTING_RELEASE(nsDOMAttributeMap)

nsresult nsDOMAttributeMap::SetOwnerDocument(Document* aDocument) {
for (const auto& entry : mAttributeCache) {
nsresult rv = entry.GetData()->SetOwnerDocument(aDocument);
for (const auto& entry : mAttributeCache.Values()) {
nsresult rv = entry->SetOwnerDocument(aDocument);
NS_ENSURE_SUCCESS(rv, NS_ERROR_FAILURE);
}
return NS_OK;
Expand Down
4 changes: 2 additions & 2 deletions dom/base/nsNodeInfoManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,8 @@ nsresult nsNodeInfoManager::Init(mozilla::dom::Document* aDocument) {

void nsNodeInfoManager::DropDocumentReference() {
// This is probably not needed anymore.
for (const auto& entry : mNodeInfoHash) {
entry.GetData()->mDocument = nullptr;
for (const auto& entry : mNodeInfoHash.Values()) {
entry->mDocument = nullptr;
}

NS_ASSERTION(!mNonDocumentNodeInfos,
Expand Down
10 changes: 2 additions & 8 deletions dom/base/nsWindowMemoryReporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -497,10 +497,7 @@ nsWindowMemoryReporter::CollectReports(nsIHandleReportCallback* aHandleReport,

// Hold on to every window in memory so that window objects can't be
// destroyed while we're calling the memory reporter callback.
WindowArray windows;
for (const auto& entry : *windowsById) {
windows.AppendElement(entry.GetData());
}
const auto windows = ToTArray<WindowArray>(windowsById->Values());

// Get the IDs of all the "ghost" windows, and call
// aHandleReport->Callback() for each one.
Expand Down Expand Up @@ -896,10 +893,7 @@ void nsWindowMemoryReporter::UnlinkGhostWindows() {

// Hold on to every window in memory so that window objects can't be
// destroyed while we're calling the UnlinkGhostWindows callback.
WindowArray windows;
for (const auto& entry : *windowsById) {
windows.AppendElement(entry.GetData());
}
const auto windows = ToTArray<WindowArray>(windowsById->Values());

// Get the IDs of all the "ghost" windows, and unlink them all.
nsTHashSet<uint64_t> ghostWindows;
Expand Down
16 changes: 8 additions & 8 deletions dom/html/HTMLMediaElement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3452,8 +3452,8 @@ void HTMLMediaElement::GetAllEnabledMediaTracks(
}

void HTMLMediaElement::SetCapturedOutputStreamsEnabled(bool aEnabled) {
for (auto& entry : mOutputTrackSources) {
entry.GetData()->SetEnabled(aEnabled);
for (const auto& entry : mOutputTrackSources.Values()) {
entry->SetEnabled(aEnabled);
}
}

Expand All @@ -3463,8 +3463,8 @@ HTMLMediaElement::OutputMuteState HTMLMediaElement::OutputTracksMuted() {
}

void HTMLMediaElement::UpdateOutputTracksMuting() {
for (auto& entry : mOutputTrackSources) {
entry.GetData()->SetMutedByElement(OutputTracksMuted());
for (const auto& entry : mOutputTrackSources.Values()) {
entry->SetMutedByElement(OutputTracksMuted());
}
}

Expand Down Expand Up @@ -3814,8 +3814,8 @@ already_AddRefed<DOMMediaStream> HTMLMediaElement::CaptureStreamInternal(
mAudioCaptured = true;
}

for (const auto& entry : mOutputTrackSources) {
const RefPtr<MediaElementTrackSource>& source = entry.GetData();
for (const RefPtr<MediaElementTrackSource>& source :
mOutputTrackSources.Values()) {
if (source->Track()->mType == MediaSegment::VIDEO) {
// Only add video tracks if we're a video element and the output stream
// wants video.
Expand Down Expand Up @@ -6221,8 +6221,8 @@ void HTMLMediaElement::NotifyDecoderPrincipalChanged() {
if (isSameOrigin) {
principal = NodePrincipal();
}
for (const auto& entry : mOutputTrackSources) {
entry.GetData()->SetPrincipal(principal);
for (const auto& entry : mOutputTrackSources.Values()) {
entry->SetPrincipal(principal);
}
mDecoder->SetOutputTracksPrincipal(principal);
}
Expand Down
28 changes: 13 additions & 15 deletions dom/indexedDB/ActorsParent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6124,8 +6124,8 @@ void InvalidateLiveDatabasesMatching(const Condition& aCondition) {

nsTArray<SafeRefPtr<Database>> databases;

for (const auto& liveDatabasesEntry : *gLiveDatabaseHashtable) {
for (const auto& database : liveDatabasesEntry.GetData()->mLiveDatabases) {
for (const auto& liveDatabasesEntry : gLiveDatabaseHashtable->Values()) {
for (const auto& database : liveDatabasesEntry->mLiveDatabases) {
if (aCondition(*database)) {
databases.AppendElement(
SafeRefPtr{database.get(), AcquireStrongRefFromRawPtr{}});
Expand Down Expand Up @@ -7535,8 +7535,8 @@ void DatabaseConnection::UpdateRefcountFunction::DidCommit() {
AUTO_PROFILER_LABEL("DatabaseConnection::UpdateRefcountFunction::DidCommit",
DOM);

for (const auto& entry : mFileInfoEntries) {
entry.GetData()->MaybeUpdateDBRefs();
for (const auto& entry : mFileInfoEntries.Values()) {
entry->MaybeUpdateDBRefs();
}

QM_WARNONLY_TRY(RemoveJournals(mJournalsToRemoveAfterCommit));
Expand Down Expand Up @@ -7576,8 +7576,8 @@ void DatabaseConnection::UpdateRefcountFunction::RollbackSavepoint() {
MOZ_ASSERT(!IsOnBackgroundThread());
MOZ_ASSERT(mInSavepoint);

for (const auto& entry : mSavepointEntriesIndex) {
entry.GetData()->DecBySavepointDelta();
for (const auto& entry : mSavepointEntriesIndex.Values()) {
entry->DecBySavepointDelta();
}

mInSavepoint = false;
Expand All @@ -7597,11 +7597,10 @@ void DatabaseConnection::UpdateRefcountFunction::Reset() {
// FileInfo implementation automatically removes unreferenced files, but it's
// done asynchronously and with a delay. We want to remove them (and decrease
// quota usage) before we fire the commit event.
for (const auto& entry : mFileInfoEntries) {
for (const auto& entry : mFileInfoEntries.Values()) {
// We need to move mFileInfo into a raw pointer in order to release it
// explicitly with aSyncDeleteFile == true.
FileInfo* const fileInfo =
entry.GetData()->ReleaseFileInfo().forget().take();
FileInfo* const fileInfo = entry->ReleaseFileInfo().forget().take();
MOZ_ASSERT(fileInfo);

fileInfo->Release(/* aSyncDeleteFile */ true);
Expand Down Expand Up @@ -9066,9 +9065,8 @@ ConnectionPool::TransactionInfoPair::~TransactionInfoPair() {
bool FullObjectStoreMetadata::HasLiveIndexes() const {
AssertIsOnBackgroundThread();

return std::any_of(mIndexes.cbegin(), mIndexes.cend(), [](const auto& entry) {
return !entry.GetData()->mDeleted;
});
return std::any_of(mIndexes.Values().cbegin(), mIndexes.Values().cend(),
[](const auto& entry) { return !entry->mDeleted; });
}

SafeRefPtr<FullDatabaseMetadata> FullDatabaseMetadata::Duplicate() const {
Expand Down Expand Up @@ -13737,10 +13735,10 @@ nsresult Maintenance::BeginDatabaseMaintenance() {

if (gLiveDatabaseHashtable) {
return std::all_of(
gLiveDatabaseHashtable->cbegin(), gLiveDatabaseHashtable->cend(),
gLiveDatabaseHashtable->Values().cbegin(),
gLiveDatabaseHashtable->Values().cend(),
[&aDatabasePath](const auto& liveDatabasesEntry) {
const auto& liveDatabases =
liveDatabasesEntry.GetData()->mLiveDatabases;
const auto& liveDatabases = liveDatabasesEntry->mLiveDatabases;
return std::all_of(liveDatabases.cbegin(), liveDatabases.cend(),
[&aDatabasePath](const auto& database) {
return database->FilePath() != aDatabasePath;
Expand Down
4 changes: 2 additions & 2 deletions dom/indexedDB/IndexedDatabaseManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -702,8 +702,8 @@ void IndexedDatabaseManager::AddFileManager(
void IndexedDatabaseManager::InvalidateAllFileManagers() {
AssertIsOnIOThread();

for (const auto& fileManagerInfo : mFileManagerInfos) {
fileManagerInfo.GetData()->InvalidateAllFileManagers();
for (const auto& fileManagerInfo : mFileManagerInfos.Values()) {
fileManagerInfo->InvalidateAllFileManagers();
}

mFileManagerInfos.Clear();
Expand Down
12 changes: 3 additions & 9 deletions dom/ipc/BrowserChild.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1498,8 +1498,7 @@ void BrowserChild::FlushAllCoalescedMouseData() {
MOZ_ASSERT(mCoalesceMouseMoveEvents);

// Move all entries from mCoalescedMouseData to mToBeDispatchedMouseData.
for (auto iter = mCoalescedMouseData.Iter(); !iter.Done(); iter.Next()) {
CoalescedMouseData* data = iter.UserData();
for (const auto& data : mCoalescedMouseData.Values()) {
if (!data || data->IsEmpty()) {
continue;
}
Expand Down Expand Up @@ -2971,16 +2970,11 @@ nsresult BrowserChild::DoSendAsyncMessage(const nsAString& aMessage,
nsTArray<RefPtr<BrowserChild>> BrowserChild::GetAll() {
StaticMutexAutoLock lock(sBrowserChildrenMutex);

nsTArray<RefPtr<BrowserChild>> list;
if (!sBrowserChildren) {
return list;
return {};
}

for (auto iter = sBrowserChildren->Iter(); !iter.Done(); iter.Next()) {
list.AppendElement(iter.Data());
}

return list;
return ToTArray<nsTArray<RefPtr<BrowserChild>>>(sBrowserChildren->Values());
}

BrowserChild* BrowserChild::GetFrom(PresShell* aPresShell) {
Expand Down
7 changes: 2 additions & 5 deletions dom/ipc/ContentParent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -805,8 +805,7 @@ void ContentParent::ReleaseCachedProcesses() {

#ifdef DEBUG
int num = 0;
for (auto iter = sBrowserContentParents->Iter(); !iter.Done(); iter.Next()) {
nsTArray<ContentParent*>* contentParents = iter.Data().get();
for (const auto& contentParents : sBrowserContentParents->Values()) {
num += contentParents->Length();
for (auto* cp : *contentParents) {
MOZ_LOG(ContentParent::GetLog(), LogLevel::Debug,
Expand All @@ -819,9 +818,7 @@ void ContentParent::ReleaseCachedProcesses() {
// We process the toRelease array outside of the iteration to avoid modifying
// the list (via RemoveFromList()) while we're iterating it.
nsTArray<ContentParent*> toRelease;
for (auto iter = sBrowserContentParents->Iter(); !iter.Done(); iter.Next()) {
nsTArray<ContentParent*>* contentParents = iter.Data().get();

for (const auto& contentParents : sBrowserContentParents->Values()) {
// Shutting down these processes will change the array so let's use another
// array for the removal.
for (auto* cp : *contentParents) {
Expand Down
3 changes: 1 addition & 2 deletions dom/ipc/ProcessHangMonitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -719,8 +719,7 @@ HangMonitorParent::HangMonitorParent(ProcessHangMonitor* aMonitor)
HangMonitorParent::~HangMonitorParent() {
MutexAutoLock lock(mBrowserCrashDumpHashLock);

for (auto iter = mBrowserCrashDumpIds.Iter(); !iter.Done(); iter.Next()) {
nsString crashId = iter.UserData();
for (const auto& crashId : mBrowserCrashDumpIds.Values()) {
if (!crashId.IsEmpty()) {
CrashReporter::DeleteMinidumpFilesForID(crashId);
}
Expand Down
Loading

0 comments on commit 5f56a5e

Please sign in to comment.