Skip to content

Commit 4f0b94e

Browse files
committed
Bug 708901 - Migrate to nsTHashSet in docshell. r=smaug,geckoview-reviewers,aklotz
Differential Revision: https://phabricator.services.mozilla.com/D108591
1 parent 4bd68ce commit 4f0b94e

File tree

7 files changed

+25
-28
lines changed

7 files changed

+25
-28
lines changed

docshell/base/BaseHistory.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ bool BaseHistory::CanStore(nsIURI* aURI) {
4949
}
5050

5151
void BaseHistory::ScheduleVisitedQuery(nsIURI* aURI) {
52-
mPendingQueries.PutEntry(aURI);
52+
mPendingQueries.Insert(aURI);
5353
if (mStartPendingVisitedQueriesScheduled) {
5454
return;
5555
}
@@ -67,7 +67,7 @@ void BaseHistory::ScheduleVisitedQuery(nsIURI* aURI) {
6767
}
6868

6969
void BaseHistory::CancelVisitedQueryIfPossible(nsIURI* aURI) {
70-
mPendingQueries.RemoveEntry(aURI);
70+
mPendingQueries.Remove(aURI);
7171
// TODO(bug 1591393): It could be worth to make this virtual and allow places
7272
// to stop the existing database query? Needs some measurement.
7373
}

docshell/base/BaseHistory.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
#include "IHistory.h"
99
#include "mozilla/dom/ContentParent.h"
10+
#include "nsTHashSet.h"
1011

1112
/* A base class for history implementations that implement link coloring. */
1213

@@ -40,7 +41,7 @@ class BaseHistory : public IHistory {
4041
}
4142
};
4243

43-
using PendingVisitedQueries = nsTHashtable<nsURIHashKey>;
44+
using PendingVisitedQueries = nsTHashSet<nsURIHashKey>;
4445
using PendingVisitedResults = nsTArray<mozilla::dom::VisitedQueryResult>;
4546

4647
// Starts all the queries in the pending queries list, potentially at the same

docshell/base/BrowsingContextGroup.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,13 @@ BrowsingContextGroup::BrowsingContextGroup(uint64_t aId) : mId(aId) {
5353
void BrowsingContextGroup::Register(nsISupports* aContext) {
5454
MOZ_DIAGNOSTIC_ASSERT(!mDestroyed);
5555
MOZ_DIAGNOSTIC_ASSERT(aContext);
56-
mContexts.PutEntry(aContext);
56+
mContexts.Insert(aContext);
5757
}
5858

5959
void BrowsingContextGroup::Unregister(nsISupports* aContext) {
6060
MOZ_DIAGNOSTIC_ASSERT(!mDestroyed);
6161
MOZ_DIAGNOSTIC_ASSERT(aContext);
62-
mContexts.RemoveEntry(aContext);
62+
mContexts.Remove(aContext);
6363

6464
MaybeDestroy();
6565
}
@@ -168,7 +168,7 @@ void BrowsingContextGroup::Subscribe(ContentParent* aProcess) {
168168
void BrowsingContextGroup::Unsubscribe(ContentParent* aProcess) {
169169
MOZ_DIAGNOSTIC_ASSERT(aProcess);
170170
MOZ_DIAGNOSTIC_ASSERT(aProcess->GetRemoteType() != PREALLOC_REMOTE_TYPE);
171-
mSubscribers.RemoveEntry(aProcess);
171+
mSubscribers.Remove(aProcess);
172172
aProcess->RemoveBrowsingContextGroup(this);
173173

174174
#ifdef MOZ_DIAGNOSTIC_ASSERT_ENABLED
@@ -237,8 +237,8 @@ void BrowsingContextGroup::Destroy() {
237237
for (auto& entry : mHosts.Values()) {
238238
entry->RemoveBrowsingContextGroup(this);
239239
}
240-
for (auto& entry : mSubscribers) {
241-
entry.GetKey()->RemoveBrowsingContextGroup(this);
240+
for (const auto& key : mSubscribers) {
241+
key->RemoveBrowsingContextGroup(this);
242242
}
243243
mHosts.Clear();
244244
mSubscribers.Clear();

docshell/base/BrowsingContextGroup.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
#include "nsRefPtrHashtable.h"
1313
#include "nsHashKeys.h"
1414
#include "nsTArray.h"
15-
#include "nsTHashtable.h"
15+
#include "nsTHashSet.h"
1616
#include "nsWrapperCache.h"
1717
#include "nsXULAppAPI.h"
1818

@@ -105,9 +105,9 @@ class BrowsingContextGroup final : public nsWrapperCache {
105105
template <typename Func>
106106
void EachOtherParent(ContentParent* aExcludedParent, Func&& aCallback) {
107107
MOZ_DIAGNOSTIC_ASSERT(XRE_IsParentProcess());
108-
for (auto iter = mSubscribers.Iter(); !iter.Done(); iter.Next()) {
109-
if (iter.Get()->GetKey() != aExcludedParent) {
110-
aCallback(iter.Get()->GetKey());
108+
for (const auto& key : mSubscribers) {
109+
if (key != aExcludedParent) {
110+
aCallback(key);
111111
}
112112
}
113113
}
@@ -117,8 +117,8 @@ class BrowsingContextGroup final : public nsWrapperCache {
117117
template <typename Func>
118118
void EachParent(Func&& aCallback) {
119119
MOZ_DIAGNOSTIC_ASSERT(XRE_IsParentProcess());
120-
for (auto iter = mSubscribers.Iter(); !iter.Done(); iter.Next()) {
121-
aCallback(iter.Get()->GetKey());
120+
for (const auto& key : mSubscribers) {
121+
aCallback(key);
122122
}
123123
}
124124

@@ -184,7 +184,7 @@ class BrowsingContextGroup final : public nsWrapperCache {
184184
// non-discarded contexts within discarded contexts alive. It should be
185185
// removed in the future.
186186
// FIXME: Consider introducing a better common base than `nsISupports`?
187-
nsTHashtable<nsRefPtrHashKey<nsISupports>> mContexts;
187+
nsTHashSet<nsRefPtrHashKey<nsISupports>> mContexts;
188188

189189
// The set of toplevel browsing contexts in the current BrowsingContextGroup.
190190
nsTArray<RefPtr<BrowsingContext>> mToplevels;
@@ -206,7 +206,7 @@ class BrowsingContextGroup final : public nsWrapperCache {
206206
// process.
207207
nsRefPtrHashtable<nsCStringHashKey, ContentParent> mHosts;
208208

209-
nsTHashtable<nsRefPtrHashKey<ContentParent>> mSubscribers;
209+
nsTHashSet<nsRefPtrHashKey<ContentParent>> mSubscribers;
210210

211211
// A queue to store postMessage events during page load, the queue will be
212212
// flushed once the page is loaded

docshell/base/CanonicalBrowsingContext.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
#include "nsQueryObject.h"
4141
#include "nsBrowserStatusFilter.h"
4242
#include "nsIBrowser.h"
43+
#include "nsTHashSet.h"
4344

4445
using namespace mozilla::ipc;
4546

@@ -931,7 +932,7 @@ void CanonicalBrowsingContext::NotifyMediaMutedChanged(bool aMuted,
931932
uint32_t CanonicalBrowsingContext::CountSiteOrigins(
932933
GlobalObject& aGlobal,
933934
const Sequence<OwningNonNull<BrowsingContext>>& aRoots) {
934-
nsTHashtable<nsCStringHashKey> uniqueSiteOrigins;
935+
nsTHashSet<nsCString> uniqueSiteOrigins;
935936

936937
for (const auto& root : aRoots) {
937938
root->PreOrderWalk([&](BrowsingContext* aContext) {
@@ -945,7 +946,7 @@ uint32_t CanonicalBrowsingContext::CountSiteOrigins(
945946
if (isContentPrincipal) {
946947
nsCString siteOrigin;
947948
documentPrincipal->GetSiteOrigin(siteOrigin);
948-
uniqueSiteOrigins.PutEntry(siteOrigin);
949+
uniqueSiteOrigins.Insert(siteOrigin);
949950
}
950951
}
951952
});

mobile/android/components/geckoview/GeckoViewHistory.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,7 @@ void GeckoViewHistory::QueryVisitedStateInContentProcess(
8484
// nsTArray<URIParams>` instead, but, since we don't expect to have many tab
8585
// children, we can avoid the cost of hashing.
8686
AutoTArray<NewURIEntry, 8> newEntries;
87-
for (auto query = aQueries.ConstIter(); !query.Done(); query.Next()) {
88-
nsIURI* uri = query.Get()->GetKey();
87+
for (nsIURI* uri : aQueries) {
8988
auto entry = mTrackedURIs.Lookup(uri);
9089
if (!entry) {
9190
continue;
@@ -143,8 +142,7 @@ void GeckoViewHistory::QueryVisitedStateInParentProcess(
143142
MOZ_ASSERT(XRE_IsParentProcess());
144143

145144
nsTArray<NewURIEntry> newEntries;
146-
for (auto query = aQueries.ConstIter(); !query.Done(); query.Next()) {
147-
nsIURI* uri = query.Get()->GetKey();
145+
for (nsIURI* uri : aQueries) {
148146
auto entry = mTrackedURIs.Lookup(uri);
149147
if (!entry) {
150148
continue; // Nobody cares about this uri anymore.

toolkit/components/places/History.cpp

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2095,18 +2095,15 @@ History::IsURIVisited(nsIURI* aURI, mozIVisitedStatusCallback* aCallback) {
20952095
void History::StartPendingVisitedQueries(
20962096
const PendingVisitedQueries& aQueries) {
20972097
if (XRE_IsContentProcess()) {
2098-
nsTArray<RefPtr<nsIURI>> uris(aQueries.Count());
2099-
for (auto iter = aQueries.ConstIter(); !iter.Done(); iter.Next()) {
2100-
uris.AppendElement(iter.Get()->GetKey());
2101-
}
2098+
const auto uris = ToTArray<nsTArray<RefPtr<nsIURI>>>(aQueries);
21022099
auto* cpc = mozilla::dom::ContentChild::GetSingleton();
21032100
MOZ_ASSERT(cpc, "Content Protocol is NULL!");
21042101
Unused << cpc->SendStartVisitedQueries(uris);
21052102
} else {
21062103
// TODO(bug 1594368): We could do a single query, as long as we can
21072104
// then notify each URI individually.
2108-
for (auto iter = aQueries.ConstIter(); !iter.Done(); iter.Next()) {
2109-
nsresult queryStatus = VisitedQuery::Start(iter.Get()->GetKey());
2105+
for (const auto& key : aQueries) {
2106+
nsresult queryStatus = VisitedQuery::Start(key);
21102107
Unused << NS_WARN_IF(NS_FAILED(queryStatus));
21112108
}
21122109
}

0 commit comments

Comments
 (0)