From 8bfe252320d5b9a5367a6485d77123cf4bf8ffc7 Mon Sep 17 00:00:00 2001 From: Simon Giesecke Date: Tue, 16 Jun 2020 10:15:42 +0000 Subject: [PATCH] Bug 1645339 - Use range-based for with nsTObserverArray in dom/reporting. r=smaug Differential Revision: https://phabricator.services.mozilla.com/D79503 --- dom/reporting/ReportingHeader.cpp | 24 ++++++++---------------- 1 file changed, 8 insertions(+), 16 deletions(-) diff --git a/dom/reporting/ReportingHeader.cpp b/dom/reporting/ReportingHeader.cpp index 8671cef7ed8b..0f780b039935 100644 --- a/dom/reporting/ReportingHeader.cpp +++ b/dom/reporting/ReportingHeader.cpp @@ -286,11 +286,10 @@ void ReportingHeader::ReportingFromChannel(nsIHttpChannel* aChannel) { continue; } + /// XXX We could use a NonObservingRange here and then + /// std::any_of. bool found = false; - nsTObserverArray::ForwardIterator iter(client->mGroups); - while (iter.HasMore()) { - const Group& group = iter.GetNext(); - + for (const Group& group : client->mGroups.ForwardRange()) { if (group.mName == groupName) { found = true; break; @@ -512,10 +511,7 @@ void ReportingHeader::GetEndpointForReport(const nsAString& aGroupName, return; } - nsTObserverArray::ForwardIterator iter(client->mGroups); - while (iter.HasMore()) { - const Group& group = iter.GetNext(); - + for (const Group& group : client->mGroups.ForwardRange()) { if (group.mName == aGroupName) { GetEndpointForReportInternal(group, aEndpointURI); break; @@ -539,10 +535,8 @@ void ReportingHeader::GetEndpointForReportInternal( int64_t minPriority = -1; uint32_t totalWeight = 0; - nsTObserverArray::ForwardIterator iter(aGroup.mEndpoints); - while (iter.HasMore()) { - const Endpoint& endpoint = iter.GetNext(); - + /// XXX We could use a NonObservingRange here. + for (const Endpoint& endpoint : aGroup.mEndpoints.ForwardRange()) { if (minPriority == -1 || minPriority > endpoint.mPriority) { minPriority = endpoint.mPriority; totalWeight = endpoint.mWeight; @@ -571,10 +565,8 @@ void ReportingHeader::GetEndpointForReportInternal( totalWeight = randomNumber % totalWeight; - nsTObserverArray::ForwardIterator iter2(aGroup.mEndpoints); - while (iter2.HasMore()) { - const Endpoint& endpoint = iter2.GetNext(); - + /// XXX We could use a NonObservingRange here. + for (const Endpoint& endpoint : aGroup.mEndpoints.ForwardRange()) { if (minPriority == endpoint.mPriority && totalWeight < endpoint.mWeight) { Unused << NS_WARN_IF(NS_FAILED(endpoint.mUrl->GetSpec(aEndpointURI))); break;