diff --git a/accessible/base/ARIAMap.h b/accessible/base/ARIAMap.h index 7e0d9469b250..30cc1f08144e 100644 --- a/accessible/base/ARIAMap.h +++ b/accessible/base/ARIAMap.h @@ -319,7 +319,7 @@ class AttrIterator { dom::Element* mElement; bool mIteratingDefaults; - nsTHashSet> mOverriddenAttrs; + nsTHashSet> mOverriddenAttrs; const AttrArray* mAttrs; uint32_t mAttrIdx; diff --git a/accessible/base/AccAttributes.h b/accessible/base/AccAttributes.h index 6ee78aaaa0e7..0d7610b3582e 100644 --- a/accessible/base/AccAttributes.h +++ b/accessible/base/AccAttributes.h @@ -10,7 +10,6 @@ #include "mozilla/a11y/AccGroupInfo.h" #include "mozilla/Variant.h" #include "nsTHashMap.h" -#include "nsAtom.h" #include "nsStringFwd.h" #include "mozilla/gfx/Matrix.h" @@ -72,7 +71,7 @@ class AccAttributes { RefPtr, uint64_t, UniquePtr, UniquePtr, nsTArray>; static_assert(sizeof(AttrValueType) <= 16); - using AtomVariantMap = nsTHashMap, AttrValueType>; + using AtomVariantMap = nsTHashMap, AttrValueType>; protected: ~AccAttributes() = default; diff --git a/accessible/base/nsAccessibilityService.h b/accessible/base/nsAccessibilityService.h index e541e1e785bf..4f24968a9812 100644 --- a/accessible/base/nsAccessibilityService.h +++ b/accessible/base/nsAccessibilityService.h @@ -13,6 +13,7 @@ #include "mozilla/a11y/SelectionManager.h" #include "mozilla/Preferences.h" +#include "nsAtomHashKeys.h" #include "nsIContent.h" #include "nsIObserver.h" #include "nsIAccessibleEvent.h" @@ -69,14 +70,14 @@ struct MarkupAttrInfo { }; struct MarkupMapInfo { - const nsStaticAtom* const tag; + nsStaticAtom* const tag; New_Accessible* new_func; a11y::role role; MarkupAttrInfo attrs[4]; }; struct XULMarkupMapInfo { - const nsStaticAtom* const tag; + nsStaticAtom* const tag; New_Accessible* new_func; }; @@ -381,8 +382,8 @@ class nsAccessibilityService final : public mozilla::a11y::DocManager, */ static uint32_t gConsumers; - using MarkupMap = nsTHashMap, - const mozilla::a11y::MarkupMapInfo*>; + // Can be weak because all atoms are known static + using MarkupMap = nsTHashMap; MarkupMap mHTMLMarkupMap; MarkupMap mMathMLMarkupMap; @@ -403,8 +404,7 @@ class nsAccessibilityService final : public mozilla::a11y::DocManager, const mozilla::a11y::MarkupMapInfo* GetMarkupMapInfoFor( mozilla::a11y::Accessible* aAcc) const; - nsTHashMap, const mozilla::a11y::XULMarkupMapInfo*> - mXULMarkupMap; + nsTHashMap mXULMarkupMap; friend nsAccessibilityService* GetAccService(); friend nsAccessibilityService* GetOrCreateAccService(uint32_t); diff --git a/dom/base/CustomElementRegistry.h b/dom/base/CustomElementRegistry.h index fbc62fe84b7d..f72c7a8ef9bc 100644 --- a/dom/base/CustomElementRegistry.h +++ b/dom/base/CustomElementRegistry.h @@ -22,6 +22,7 @@ #include "nsCycleCollectionParticipant.h" #include "nsWrapperCache.h" #include "nsTHashSet.h" +#include "nsAtomHashKeys.h" namespace mozilla { class ErrorResult; @@ -493,18 +494,16 @@ class CustomElementRegistry final : public nsISupports, public nsWrapperCache { void UpgradeCandidates(nsAtom* aKey, CustomElementDefinition* aDefinition, ErrorResult& aRv); - typedef nsRefPtrHashtable, CustomElementDefinition> - DefinitionMap; - typedef nsRefPtrHashtable, - CustomElementCreationCallback> - ElementCreationCallbackMap; - typedef nsClassHashtable, - nsTHashSet>> - CandidateMap; - typedef JS::GCHashMap, RefPtr, - js::StableCellHasher>, - js::SystemAllocPolicy> - ConstructorMap; + using DefinitionMap = + nsRefPtrHashtable; + using ElementCreationCallbackMap = + nsRefPtrHashtable; + using CandidateMap = + nsClassHashtable>>; + using ConstructorMap = + JS::GCHashMap, RefPtr, + js::StableCellHasher>, + js::SystemAllocPolicy>; // Hashtable for custom element definitions in web components. // Custom prototypes are stored in the compartment where definition was @@ -521,8 +520,7 @@ class CustomElementRegistry final : public nsISupports, public nsWrapperCache { // mCustomDefinitions again to get definitions. ConstructorMap mConstructors; - typedef nsRefPtrHashtable, Promise> - WhenDefinedPromiseMap; + using WhenDefinedPromiseMap = nsRefPtrHashtable; WhenDefinedPromiseMap mWhenDefinedPromiseMap; // The "upgrade candidates map" from the web components spec. Maps from a diff --git a/dom/base/FragmentOrElement.h b/dom/base/FragmentOrElement.h index bbef051daf55..3d5043224409 100644 --- a/dom/base/FragmentOrElement.h +++ b/dom/base/FragmentOrElement.h @@ -19,6 +19,7 @@ #include "mozilla/UniquePtr.h" #include "nsCycleCollectionParticipant.h" // NS_DECL_CYCLE_* #include "nsIContent.h" // base class +#include "nsAtomHashKeys.h" #include "nsIHTMLCollection.h" #include "nsIWeakReferenceUtils.h" @@ -230,7 +231,7 @@ class FragmentOrElement : public nsIContent { * Explicitly set attr-elements, see * https://html.spec.whatwg.org/multipage/common-dom-interfaces.html#explicitly-set-attr-element */ - nsTHashMap, nsWeakPtr> mExplicitlySetAttrElements; + nsTHashMap, nsWeakPtr> mExplicitlySetAttrElements; }; class nsDOMSlots : public nsIContent::nsContentSlots { diff --git a/dom/base/Highlight.cpp b/dom/base/Highlight.cpp index 7f5b4030914f..cd0efccce58c 100644 --- a/dom/base/Highlight.cpp +++ b/dom/base/Highlight.cpp @@ -64,13 +64,13 @@ already_AddRefed Highlight::Constructor( } void Highlight::AddToHighlightRegistry(HighlightRegistry& aHighlightRegistry, - const nsAtom& aHighlightName) { + nsAtom& aHighlightName) { mHighlightRegistries.LookupOrInsert(&aHighlightRegistry) .Insert(&aHighlightName); } void Highlight::RemoveFromHighlightRegistry( - HighlightRegistry& aHighlightRegistry, const nsAtom& aHighlightName) { + HighlightRegistry& aHighlightRegistry, nsAtom& aHighlightName) { if (auto entry = mHighlightRegistries.Lookup(&aHighlightRegistry)) { auto& highlightNames = entry.Data(); highlightNames.Remove(&aHighlightName); diff --git a/dom/base/Highlight.h b/dom/base/Highlight.h index 3a315120cf54..7c542ff4f324 100644 --- a/dom/base/Highlight.h +++ b/dom/base/Highlight.h @@ -12,7 +12,7 @@ #include "mozilla/dom/HighlightBinding.h" #include "nsCycleCollectionParticipant.h" -#include "nsHashKeys.h" +#include "nsAtomHashKeys.h" #include "nsTHashSet.h" #include "nsTArray.h" #include "nsWrapperCache.h" @@ -80,13 +80,13 @@ class Highlight final : public nsISupports, public nsWrapperCache { * the name has to be provided as well. */ void AddToHighlightRegistry(HighlightRegistry& aHighlightRegistry, - const nsAtom& aHighlightName); + nsAtom& aHighlightName); /** * @brief Removes `this` from `aHighlightRegistry`. */ void RemoveFromHighlightRegistry(HighlightRegistry& aHighlightRegistry, - const nsAtom& aHighlightName); + nsAtom& aHighlightName); /** * @brief Creates a Highlight Selection using the given ranges. @@ -204,8 +204,7 @@ class Highlight final : public nsISupports, public nsWrapperCache { * Note: Storing `HighlightRegistry` as raw pointer is safe here * because it unregisters itself from `this` when it is destroyed/CC'd */ - nsTHashMap, - nsTHashSet>> + nsTHashMap, nsTHashSet>> mHighlightRegistries; }; diff --git a/dom/base/nsAttrValue.cpp b/dom/base/nsAttrValue.cpp index 3c50d8f76410..9cdedffab6ba 100644 --- a/dom/base/nsAttrValue.cpp +++ b/dom/base/nsAttrValue.cpp @@ -15,7 +15,7 @@ #include "nsAttrValue.h" #include "nsAttrValueInlines.h" -#include "nsAtom.h" +#include "nsAtomHashKeys.h" #include "nsUnicharUtils.h" #include "mozilla/AttributeStyles.h" #include "mozilla/BloomFilter.h" @@ -53,7 +53,7 @@ struct AtomArrayCache { // MiscContainer. The MiscContainer removes itself from the cache when // the last reference to it is dropped, and the atom is kept alive by // the MiscContainer. - using MapType = nsTHashMap, MiscContainer*>; + using MapType = nsTHashMap; static MiscContainer* Lookup(nsAtom* aValue) { if (auto* instance = GetInstance()) { @@ -822,7 +822,7 @@ UniquePtr AttrAtomArray::CreateDeduplicatedCopyIfDifferentImpl() bool usingHashTable = false; BitBloomFilter<8, nsAtom> filter; - nsTHashSet> hash; + nsTHashSet hash; auto CheckDuplicate = [&](size_t i) { nsAtom* atom = mArray[i]; diff --git a/dom/base/nsContentList.h b/dom/base/nsContentList.h index 8e2bd606ada7..a70c5281b212 100644 --- a/dom/base/nsContentList.h +++ b/dom/base/nsContentList.h @@ -21,7 +21,7 @@ #include "nsIHTMLCollection.h" #include "nsINodeList.h" #include "nsStubMutationObserver.h" -#include "nsAtom.h" +#include "nsAtomHashKeys.h" #include "nsCycleCollectionParticipant.h" #include "nsNameSpaceManager.h" #include "nsWrapperCache.h" @@ -357,7 +357,7 @@ class nsContentList : public nsBaseContentList, // A cache from name to the first named item in mElements. Only possibly // non-null when mState is State::UpToDate. Elements are kept alive by our // mElements array. - using NamedItemsCache = nsTHashMap, Element*>; + using NamedItemsCache = nsTHashMap; void InvalidateNamedItemsCache() { mNamedItemsCache = nullptr; diff --git a/dom/base/nsContentUtils.cpp b/dom/base/nsContentUtils.cpp index ee967b7a5f6a..52650a856f8e 100644 --- a/dom/base/nsContentUtils.cpp +++ b/dom/base/nsContentUtils.cpp @@ -218,7 +218,7 @@ #include "nsAboutProtocolUtils.h" #include "nsAlgorithm.h" #include "nsArrayUtils.h" -#include "nsAtom.h" +#include "nsAtomHashKeys.h" #include "nsAttrName.h" #include "nsAttrValue.h" #include "nsAttrValueInlines.h" @@ -426,11 +426,10 @@ nsIPrincipal* nsContentUtils::sSystemPrincipal; nsIPrincipal* nsContentUtils::sNullSubjectPrincipal; nsIIOService* nsContentUtils::sIOService; nsIConsoleService* nsContentUtils::sConsoleService; -nsTHashMap, EventNameMapping>* - nsContentUtils::sAtomEventTable = nullptr; -nsTHashMap* - nsContentUtils::sStringEventTable = nullptr; -nsTArray>* nsContentUtils::sUserDefinedEvents = nullptr; + +static nsTHashMap, EventNameMapping>* sAtomEventTable; +static nsTHashMap* sStringEventTable; +static nsTArray>* sUserDefinedEvents; nsIStringBundleService* nsContentUtils::sStringBundleService; static StaticRefPtr @@ -985,8 +984,8 @@ bool nsContentUtils::InitializeEventTable() { #undef EVENT {nullptr}}; - sAtomEventTable = new nsTHashMap, EventNameMapping>( - ArrayLength(eventArray)); + sAtomEventTable = + new nsTHashMap, EventNameMapping>(ArrayLength(eventArray)); sStringEventTable = new nsTHashMap( ArrayLength(eventArray)); sUserDefinedEvents = new nsTArray>(64); diff --git a/dom/base/nsContentUtils.h b/dom/base/nsContentUtils.h index 043786a843a5..b09dacc2be6d 100644 --- a/dom/base/nsContentUtils.h +++ b/dom/base/nsContentUtils.h @@ -43,7 +43,6 @@ #include "mozilla/fallible.h" #include "mozilla/gfx/Point.h" #include "nsCOMPtr.h" -#include "nsHashtablesFwd.h" #include "nsIContentPolicy.h" #include "nsINode.h" #include "nsIScriptError.h" @@ -118,7 +117,6 @@ class nsParser; class nsPIWindowRoot; class nsPresContext; class nsStringBuffer; -class nsStringHashKey; class nsTextFragment; class nsView; class nsWrapperCache; @@ -126,9 +124,6 @@ class nsWrapperCache; struct JSContext; struct nsPoint; -template -class nsRefPtrHashKey; - namespace IPC { class Message; class MessageReader; @@ -3529,10 +3524,6 @@ class nsContentUtils { static nsIConsoleService* sConsoleService; - static nsTHashMap, EventNameMapping>* sAtomEventTable; - static nsTHashMap* sStringEventTable; - static nsTArray>* sUserDefinedEvents; - static nsIStringBundleService* sStringBundleService; class nsContentUtilsReporter; diff --git a/dom/base/nsNameSpaceManager.h b/dom/base/nsNameSpaceManager.h index aa4ec51104a5..32d058007053 100644 --- a/dom/base/nsNameSpaceManager.h +++ b/dom/base/nsNameSpaceManager.h @@ -8,8 +8,6 @@ #define nsNameSpaceManager_h___ #include "nsTHashMap.h" -#include "nsHashKeys.h" -#include "nsAtom.h" #include "nsStringFwd.h" #include "nsTArray.h" @@ -73,8 +71,8 @@ class nsNameSpaceManager final { const int32_t aNameSpaceID); ~nsNameSpaceManager() = default; - nsTHashMap, int32_t> mURIToIDTable; - nsTHashMap, int32_t> mDisabledURIToIDTable; + nsTHashMap, int32_t> mURIToIDTable; + nsTHashMap, int32_t> mDisabledURIToIDTable; nsTArray> mURIArray; static mozilla::StaticRefPtr sInstance; diff --git a/intl/hyphenation/glue/nsHyphenationManager.h b/intl/hyphenation/glue/nsHyphenationManager.h index 8937ca580875..5b1d0f9adbbb 100644 --- a/intl/hyphenation/glue/nsHyphenationManager.h +++ b/intl/hyphenation/glue/nsHyphenationManager.h @@ -9,10 +9,10 @@ #include "base/shared_memory.h" #include "mozilla/Omnijar.h" #include "nsHashKeys.h" +#include "nsAtomHashKeys.h" #include "nsInterfaceHashtable.h" #include "nsIObserver.h" #include "nsRefPtrHashtable.h" - class nsHyphenator; class nsAtom; class nsIURI; @@ -45,9 +45,9 @@ class nsHyphenationManager : public nsIObserver { void LoadPatternListFromDir(nsIFile* aDir); void LoadAliases(); - nsRefPtrHashtable, nsAtom> mHyphAliases; - nsInterfaceHashtable, nsIURI> mPatternFiles; - nsRefPtrHashtable, nsHyphenator> mHyphenators; + nsRefPtrHashtable mHyphAliases; + nsInterfaceHashtable mPatternFiles; + nsRefPtrHashtable mHyphenators; static nsHyphenationManager* sInstance; }; diff --git a/intl/locale/nsLanguageAtomService.h b/intl/locale/nsLanguageAtomService.h index de06c06d9d8b..521ead4e8701 100644 --- a/intl/locale/nsLanguageAtomService.h +++ b/intl/locale/nsLanguageAtomService.h @@ -13,7 +13,7 @@ #include "mozilla/NotNull.h" #include "nsCOMPtr.h" -#include "nsAtom.h" +#include "nsAtomHashKeys.h" #include "nsTHashMap.h" namespace mozilla { @@ -54,7 +54,7 @@ class nsLanguageAtomService final { nsStaticAtom* GetUncachedLanguageGroup(nsAtom* aLanguage) const; private: - nsTHashMap, nsStaticAtom*> mLangToGroup; + nsTHashMap, nsStaticAtom*> mLangToGroup; RefPtr mLocaleLanguage; }; diff --git a/layout/base/ContainStyleScopeManager.h b/layout/base/ContainStyleScopeManager.h index 24ab05c2cb5b..890344c93e76 100644 --- a/layout/base/ContainStyleScopeManager.h +++ b/layout/base/ContainStyleScopeManager.h @@ -7,8 +7,7 @@ #ifndef ContainStyleScopeManager_h_ #define ContainStyleScopeManager_h_ -#include "mozilla/dom/Element.h" -#include "nsTHashMap.h" +#include "nsClassHashtable.h" #include "nsTHashSet.h" #include "nsQuoteList.h" #include "nsCounterManager.h" @@ -19,6 +18,10 @@ class nsAtom; namespace mozilla { +namespace dom { +class Element; +} + class ContainStyleScopeManager; /* Implementation of a self-contained `contain: style` scope which manages its @@ -128,7 +131,7 @@ class ContainStyleScopeManager { private: ContainStyleScope mRootScope; nsClassHashtable, ContainStyleScope> mScopes; - nsTHashSet> mDirtyCounters; + nsTHashSet> mDirtyCounters; }; } // namespace mozilla diff --git a/layout/base/nsCounterManager.h b/layout/base/nsCounterManager.h index 8e9d8105dc24..ccca4a2b2139 100644 --- a/layout/base/nsCounterManager.h +++ b/layout/base/nsCounterManager.h @@ -344,7 +344,7 @@ class nsCounterManager { private: mozilla::ContainStyleScope* mScope; - nsClassHashtable, nsCounterList> mNames; + nsClassHashtable mNames; }; #endif /* nsCounterManager_h_ */ diff --git a/layout/generic/nsGridContainerFrame.h b/layout/generic/nsGridContainerFrame.h index ab790c4e0e5d..401442f75447 100644 --- a/layout/generic/nsGridContainerFrame.h +++ b/layout/generic/nsGridContainerFrame.h @@ -13,6 +13,7 @@ #include "mozilla/MathAlgorithms.h" #include "mozilla/Maybe.h" #include "mozilla/HashTable.h" +#include "nsAtomHashKeys.h" #include "nsContainerFrame.h" #include "nsILineIterator.h" @@ -213,21 +214,8 @@ class nsGridContainerFrame final : public nsContainerFrame, return GetProperty(GridFragmentInfo()); } - struct AtomKey { - RefPtr mKey; - - explicit AtomKey(nsAtom* aAtom) : mKey(aAtom) {} - - using Lookup = nsAtom*; - - static mozilla::HashNumber hash(const Lookup& aKey) { return aKey->hash(); } - - static bool match(const AtomKey& aFirst, const Lookup& aSecond) { - return aFirst.mKey == aSecond; - } - }; - - using ImplicitNamedAreas = mozilla::HashMap; + using ImplicitNamedAreas = + mozilla::HashMap; NS_DECLARE_FRAME_PROPERTY_DELETABLE(ImplicitNamedAreasProperty, ImplicitNamedAreas) ImplicitNamedAreas* GetImplicitNamedAreas() const { diff --git a/layout/generic/nsTextPaintStyle.h b/layout/generic/nsTextPaintStyle.h index 623aa9879a31..c63036136f87 100644 --- a/layout/generic/nsTextPaintStyle.h +++ b/layout/generic/nsTextPaintStyle.h @@ -11,7 +11,7 @@ #include "mozilla/ComputedStyle.h" #include "mozilla/Span.h" -#include "nsAtom.h" +#include "nsAtomHashKeys.h" #include "nsISelectionController.h" #include "nsTHashMap.h" @@ -119,7 +119,7 @@ class MOZ_STACK_CLASS nsTextPaintStyle { nscolor mSelectionTextColor; nscolor mSelectionBGColor; RefPtr mSelectionPseudoStyle; - nsTHashMap, RefPtr> + nsTHashMap, RefPtr> mCustomHighlightPseudoStyles; // Common data diff --git a/layout/style/CounterStyleManager.h b/layout/style/CounterStyleManager.h index de510268692d..b6d9c2a0a95f 100644 --- a/layout/style/CounterStyleManager.h +++ b/layout/style/CounterStyleManager.h @@ -6,7 +6,6 @@ #ifndef mozilla_CounterStyleManager_h_ #define mozilla_CounterStyleManager_h_ -#include "nsAtom.h" #include "nsGkAtoms.h" #include "nsStringFwd.h" #include "nsTHashMap.h" @@ -347,7 +346,7 @@ class CounterStyleManager final { void DestroyCounterStyle(CounterStyle* aCounterStyle); nsPresContext* mPresContext; - nsTHashMap, CounterStyle*> mStyles; + nsTHashMap, CounterStyle*> mStyles; nsTArray mRetiredStyles; }; diff --git a/layout/style/ShadowParts.h b/layout/style/ShadowParts.h index 3cfe1f6ad107..fe153054617c 100644 --- a/layout/style/ShadowParts.h +++ b/layout/style/ShadowParts.h @@ -7,7 +7,7 @@ #ifndef mozilla_ShadowParts_h #define mozilla_ShadowParts_h -#include "nsAtom.h" +#include "nsAtomHashKeys.h" #include "nsTHashtable.h" #include "nsClassHashtable.h" #include "nsRefPtrHashtable.h" @@ -38,8 +38,8 @@ class ShadowParts final { // TODO(emilio): If the two hashtables take a lot of memory we should consider // just using an nsTArray> or something. - nsClassHashtable, PartList> mMappings; - nsRefPtrHashtable, nsAtom> mReverseMappings; + nsClassHashtable mMappings; + nsRefPtrHashtable mReverseMappings; }; } // namespace mozilla diff --git a/layout/style/TimelineCollection.h b/layout/style/TimelineCollection.h index 8415459cb181..1f61845e2e26 100644 --- a/layout/style/TimelineCollection.h +++ b/layout/style/TimelineCollection.h @@ -11,6 +11,7 @@ #include "mozilla/LinkedList.h" #include "mozilla/Maybe.h" #include "mozilla/RefPtr.h" +#include "nsAtomHashKeys.h" #include "nsTHashMap.h" class nsAtom; @@ -28,8 +29,7 @@ class TimelineCollection final : public LinkedListElement> { public: using SelfType = TimelineCollection; - using TimelineMap = - nsTHashMap, RefPtr>; + using TimelineMap = nsTHashMap, RefPtr>; TimelineCollection(dom::Element& aElement, PseudoStyleType aPseudoType) : mElement(aElement), mPseudo(aPseudoType) { @@ -38,11 +38,11 @@ class TimelineCollection final ~TimelineCollection(); - already_AddRefed Lookup(const nsAtom* aName) const { + already_AddRefed Lookup(nsAtom* aName) const { return mTimelines.Get(aName).forget(); } - already_AddRefed Extract(const nsAtom* aName) { + already_AddRefed Extract(nsAtom* aName) { Maybe> timeline = mTimelines.Extract(aName); return timeline ? timeline->forget() : nullptr; } diff --git a/layout/style/TimelineManager.cpp b/layout/style/TimelineManager.cpp index 0d2d98e31c23..78db0765e6fd 100644 --- a/layout/style/TimelineManager.cpp +++ b/layout/style/TimelineManager.cpp @@ -70,7 +70,7 @@ void TimelineManager::UpdateTimelines(Element* aElement, template static already_AddRefed PopExistingTimeline( - const nsAtom* aName, TimelineCollection* aCollection) { + nsAtom* aName, TimelineCollection* aCollection) { if (!aCollection) { return nullptr; } diff --git a/layout/style/nsAnimationManager.cpp b/layout/style/nsAnimationManager.cpp index f03e00ff2aa3..3ffeea2720a7 100644 --- a/layout/style/nsAnimationManager.cpp +++ b/layout/style/nsAnimationManager.cpp @@ -211,7 +211,7 @@ static void UpdateOldAnimationPropertiesWithNew( static already_AddRefed GetNamedProgressTimeline( dom::Document* aDocument, const NonOwningAnimationTarget& aTarget, - const nsAtom* aName) { + nsAtom* aName) { // A named progress timeline is referenceable in animation-timeline by: // 1. the declaring element itself // 2. that element’s descendants @@ -259,7 +259,7 @@ static already_AddRefed GetTimeline( switch (aStyleTimeline.tag) { case StyleAnimationTimeline::Tag::Timeline: { // Check scroll-timeline-name property or view-timeline-property. - const nsAtom* name = aStyleTimeline.AsTimeline().AsAtom(); + nsAtom* name = aStyleTimeline.AsTimeline().AsAtom(); return name != nsGkAtoms::_empty ? GetNamedProgressTimeline(aPresContext->Document(), aTarget, name) diff --git a/layout/style/nsStyleStruct.h b/layout/style/nsStyleStruct.h index 940c4265bbd5..2bfc41862194 100644 --- a/layout/style/nsStyleStruct.h +++ b/layout/style/nsStyleStruct.h @@ -1196,7 +1196,7 @@ struct StyleScrollTimeline { // elements. void SetInitialValues() {} - const nsAtom* GetName() const { return mName._0.AsAtom(); } + nsAtom* GetName() const { return mName._0.AsAtom(); } StyleScrollAxis GetAxis() const { return mAxis; } bool operator==(const StyleScrollTimeline& aOther) const { @@ -1220,7 +1220,7 @@ struct StyleViewTimeline { // elements. void SetInitialValues() {} - const nsAtom* GetName() const { return mName._0.AsAtom(); } + nsAtom* GetName() const { return mName._0.AsAtom(); } StyleScrollAxis GetAxis() const { return mAxis; } const StyleViewTimelineInset& GetInset() const { return mInset; } diff --git a/parser/htmlparser/nsHTMLTags.h b/parser/htmlparser/nsHTMLTags.h index eb7e3aaa2550..2e2f80e6aa03 100644 --- a/parser/htmlparser/nsHTMLTags.h +++ b/parser/htmlparser/nsHTMLTags.h @@ -6,7 +6,7 @@ #ifndef nsHTMLTags_h___ #define nsHTMLTags_h___ -#include "nsAtom.h" +#include "nsAtomHashKeys.h" #include "nsString.h" #include "nsTHashMap.h" #include "nsHashKeys.h" @@ -42,7 +42,8 @@ enum nsHTMLTag { class nsHTMLTags { public: using TagStringHash = nsTHashMap; - using TagAtomHash = nsTHashMap, nsHTMLTag>; + // Can be weak, because we know these are always static, see AddRefTable. + using TagAtomHash = nsTHashMap; static nsresult AddRefTable(void); static void ReleaseTable(void); diff --git a/toolkit/components/extensions/ExtensionPolicyService.h b/toolkit/components/extensions/ExtensionPolicyService.h index b43b52080b2c..a767b48cd7af 100644 --- a/toolkit/components/extensions/ExtensionPolicyService.h +++ b/toolkit/components/extensions/ExtensionPolicyService.h @@ -21,6 +21,7 @@ #include "nsPointerHashKeys.h" #include "nsRefPtrHashtable.h" #include "nsTHashSet.h" +#include "nsAtomHashKeys.h" class nsIChannel; class nsIObserverService; @@ -74,7 +75,7 @@ class ExtensionPolicyService final : public nsIAddonPolicyService, static RefPtr GetCoreByHost( const nsACString& aHost); - WebExtensionPolicy* GetByID(const nsAtom* aAddonId) { + WebExtensionPolicy* GetByID(nsAtom* aAddonId) { return mExtensions.GetWeak(aAddonId); } @@ -126,7 +127,8 @@ class ExtensionPolicyService final : public nsIAddonPolicyService, void UpdateRestrictedDomains(); void UpdateQuarantinedDomains(); - nsRefPtrHashtable, WebExtensionPolicy> mExtensions; + // The WebExtensionPolicy object keeps the key alive. + nsRefPtrHashtable mExtensions; nsRefPtrHashtable, extensions::DocumentObserver> diff --git a/toolkit/components/extensions/webrequest/ChannelWrapper.h b/toolkit/components/extensions/webrequest/ChannelWrapper.h index 0a03aea11330..64ec99d61b4c 100644 --- a/toolkit/components/extensions/webrequest/ChannelWrapper.h +++ b/toolkit/components/extensions/webrequest/ChannelWrapper.h @@ -21,6 +21,7 @@ #include "mozilla/WeakPtr.h" #include "mozilla/DOMEventTargetHelper.h" +#include "nsAtomHashKeys.h" #include "nsCOMPtr.h" #include "nsCycleCollectionParticipant.h" #include "nsIChannel.h" @@ -29,7 +30,6 @@ #include "nsIStreamListener.h" #include "nsIRemoteTab.h" #include "nsIThreadRetargetableStreamListener.h" -#include "nsPointerHashKeys.h" #include "nsInterfaceHashtable.h" #include "nsIWeakReferenceUtils.h" #include "nsWrapperCache.h" @@ -320,7 +320,7 @@ class ChannelWrapper final : public DOMEventTargetHelper, bool mSuspended = false; bool mResponseStarted = false; - nsInterfaceHashtable, nsIRemoteTab> mAddonEntries; + nsInterfaceHashtable mAddonEntries; // The text for the "Extension Suspend" marker, set from the Suspend method // when called for the first time and then cleared on the Resume method. diff --git a/xpcom/ds/moz.build b/xpcom/ds/moz.build index e861f7bd8d61..cce10d76d673 100644 --- a/xpcom/ds/moz.build +++ b/xpcom/ds/moz.build @@ -46,6 +46,7 @@ EXPORTS += [ "nsArrayEnumerator.h", "nsArrayUtils.h", "nsAtom.h", + "nsAtomHashKeys.h", "nsBaseHashtable.h", "nsCharSeparatedTokenizer.h", "nsCheapSets.h", diff --git a/xpcom/ds/nsAtomHashKeys.h b/xpcom/ds/nsAtomHashKeys.h new file mode 100644 index 000000000000..85aed03bd087 --- /dev/null +++ b/xpcom/ds/nsAtomHashKeys.h @@ -0,0 +1,51 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* Definitions for nsAtom-related hash keys */ + +#ifndef nsAtomHashKeys_h +#define nsAtomHashKeys_h + +#include "nsAtom.h" +#include "nsHashKeys.h" + +// TODO(emilio): Consider removing this and specializing AddToHash instead +// once bug 1849386 is fixed. + +// Hash keys suitable for use in nsTHashTable. +struct nsAtomHashKey : public nsRefPtrHashKey { + using nsRefPtrHashKey::nsRefPtrHashKey; + static PLDHashNumber HashKey(KeyTypePointer aKey) { + return MOZ_LIKELY(aKey) ? aKey->hash() : 0; + } +}; + +struct nsWeakAtomHashKey : public nsPtrHashKey { + using nsPtrHashKey::nsPtrHashKey; + static PLDHashNumber HashKey(KeyTypePointer aKey) { + return nsAtomHashKey::HashKey(aKey); + } +}; + +// Hash keys suitable for use in mozilla::HashMap. +namespace mozilla { + +struct AtomHashKey { + RefPtr mKey; + + explicit AtomHashKey(nsAtom* aAtom) : mKey(aAtom) {} + + using Lookup = nsAtom*; + + static HashNumber hash(const Lookup& aKey) { return aKey->hash(); } + static bool match(const AtomHashKey& aFirst, const Lookup& aSecond) { + return aFirst.mKey == aSecond; + } +}; + +} // namespace mozilla + +#endif // nsAtomHashKeys_h diff --git a/xpcom/ds/nsTHashMap.h b/xpcom/ds/nsTHashMap.h index 8357d2ae7bcd..6549c71faaef 100644 --- a/xpcom/ds/nsTHashMap.h +++ b/xpcom/ds/nsTHashMap.h @@ -13,6 +13,7 @@ #include "nsBaseHashtable.h" #include "nsCOMPtr.h" #include "nsHashKeys.h" +#include "nsAtomHashKeys.h" #include "nsHashtablesFwd.h" #include @@ -29,6 +30,11 @@ struct nsKeyClass { using type = nsPtrHashKey; }; +template <> +struct nsKeyClass { + using type = nsWeakAtomHashKey; +}; + template <> struct nsKeyClass { using type = nsCStringHashKey; @@ -57,6 +63,11 @@ struct nsKeyClass> { using type = nsRefPtrHashKey; }; +template <> +struct nsKeyClass> { + using type = nsAtomHashKey; +}; + template <> struct nsKeyClass { using type = nsIDHashKey;