Bug 1849204 - Add generic atom hash keys that use the better distributed atom hash, and use it across the tree. r=mstange,xpcom-reviewers,credential-management-reviewers,sgalich,nika

Differential Revision: https://phabricator.services.mozilla.com/D186496
This commit is contained in:
Emilio Cobos Álvarez 2023-08-18 18:43:27 +00:00
parent b09db560e8
commit 95707c96bb
30 changed files with 145 additions and 104 deletions

View File

@ -319,7 +319,7 @@ class AttrIterator {
dom::Element* mElement;
bool mIteratingDefaults;
nsTHashSet<nsRefPtrHashKey<nsAtom>> mOverriddenAttrs;
nsTHashSet<RefPtr<nsAtom>> mOverriddenAttrs;
const AttrArray* mAttrs;
uint32_t mAttrIdx;

View File

@ -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<AccAttributes>, uint64_t, UniquePtr<AccGroupInfo>,
UniquePtr<gfx::Matrix4x4>, nsTArray<uint64_t>>;
static_assert(sizeof(AttrValueType) <= 16);
using AtomVariantMap = nsTHashMap<nsRefPtrHashKey<nsAtom>, AttrValueType>;
using AtomVariantMap = nsTHashMap<RefPtr<nsAtom>, AttrValueType>;
protected:
~AccAttributes() = default;

View File

@ -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<nsPtrHashKey<const nsAtom>,
const mozilla::a11y::MarkupMapInfo*>;
// Can be weak because all atoms are known static
using MarkupMap = nsTHashMap<nsAtom*, const mozilla::a11y::MarkupMapInfo*>;
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<nsPtrHashKey<const nsAtom>, const mozilla::a11y::XULMarkupMapInfo*>
mXULMarkupMap;
nsTHashMap<nsAtom*, const mozilla::a11y::XULMarkupMapInfo*> mXULMarkupMap;
friend nsAccessibilityService* GetAccService();
friend nsAccessibilityService* GetOrCreateAccService(uint32_t);

View File

@ -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<nsRefPtrHashKey<nsAtom>, CustomElementDefinition>
DefinitionMap;
typedef nsRefPtrHashtable<nsRefPtrHashKey<nsAtom>,
CustomElementCreationCallback>
ElementCreationCallbackMap;
typedef nsClassHashtable<nsRefPtrHashKey<nsAtom>,
nsTHashSet<RefPtr<nsIWeakReference>>>
CandidateMap;
typedef JS::GCHashMap<JS::Heap<JSObject*>, RefPtr<nsAtom>,
js::StableCellHasher<JS::Heap<JSObject*>>,
js::SystemAllocPolicy>
ConstructorMap;
using DefinitionMap =
nsRefPtrHashtable<nsAtomHashKey, CustomElementDefinition>;
using ElementCreationCallbackMap =
nsRefPtrHashtable<nsAtomHashKey, CustomElementCreationCallback>;
using CandidateMap =
nsClassHashtable<nsAtomHashKey, nsTHashSet<RefPtr<nsIWeakReference>>>;
using ConstructorMap =
JS::GCHashMap<JS::Heap<JSObject*>, RefPtr<nsAtom>,
js::StableCellHasher<JS::Heap<JSObject*>>,
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<nsRefPtrHashKey<nsAtom>, Promise>
WhenDefinedPromiseMap;
using WhenDefinedPromiseMap = nsRefPtrHashtable<nsAtomHashKey, Promise>;
WhenDefinedPromiseMap mWhenDefinedPromiseMap;
// The "upgrade candidates map" from the web components spec. Maps from a

View File

@ -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<nsRefPtrHashKey<nsAtom>, nsWeakPtr> mExplicitlySetAttrElements;
nsTHashMap<RefPtr<nsAtom>, nsWeakPtr> mExplicitlySetAttrElements;
};
class nsDOMSlots : public nsIContent::nsContentSlots {

View File

@ -64,13 +64,13 @@ already_AddRefed<Highlight> 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);

View File

@ -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<nsPtrHashKey<HighlightRegistry>,
nsTHashSet<nsRefPtrHashKey<const nsAtom>>>
nsTHashMap<nsPtrHashKey<HighlightRegistry>, nsTHashSet<RefPtr<nsAtom>>>
mHighlightRegistries;
};

View File

@ -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<nsPtrHashKey<nsAtom>, MiscContainer*>;
using MapType = nsTHashMap<nsAtom*, MiscContainer*>;
static MiscContainer* Lookup(nsAtom* aValue) {
if (auto* instance = GetInstance()) {
@ -822,7 +822,7 @@ UniquePtr<AttrAtomArray> AttrAtomArray::CreateDeduplicatedCopyIfDifferentImpl()
bool usingHashTable = false;
BitBloomFilter<8, nsAtom> filter;
nsTHashSet<nsPtrHashKey<nsAtom>> hash;
nsTHashSet<nsAtom*> hash;
auto CheckDuplicate = [&](size_t i) {
nsAtom* atom = mArray[i];

View File

@ -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<RefPtr<nsAtom>, Element*>;
using NamedItemsCache = nsTHashMap<nsAtomHashKey, Element*>;
void InvalidateNamedItemsCache() {
mNamedItemsCache = nullptr;

View File

@ -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<nsRefPtrHashKey<nsAtom>, EventNameMapping>*
nsContentUtils::sAtomEventTable = nullptr;
nsTHashMap<nsStringHashKey, EventNameMapping>*
nsContentUtils::sStringEventTable = nullptr;
nsTArray<RefPtr<nsAtom>>* nsContentUtils::sUserDefinedEvents = nullptr;
static nsTHashMap<RefPtr<nsAtom>, EventNameMapping>* sAtomEventTable;
static nsTHashMap<nsStringHashKey, EventNameMapping>* sStringEventTable;
static nsTArray<RefPtr<nsAtom>>* sUserDefinedEvents;
nsIStringBundleService* nsContentUtils::sStringBundleService;
static StaticRefPtr<nsIStringBundle>
@ -985,8 +984,8 @@ bool nsContentUtils::InitializeEventTable() {
#undef EVENT
{nullptr}};
sAtomEventTable = new nsTHashMap<nsRefPtrHashKey<nsAtom>, EventNameMapping>(
ArrayLength(eventArray));
sAtomEventTable =
new nsTHashMap<RefPtr<nsAtom>, EventNameMapping>(ArrayLength(eventArray));
sStringEventTable = new nsTHashMap<nsStringHashKey, EventNameMapping>(
ArrayLength(eventArray));
sUserDefinedEvents = new nsTArray<RefPtr<nsAtom>>(64);

View File

@ -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 T>
class nsRefPtrHashKey;
namespace IPC {
class Message;
class MessageReader;
@ -3529,10 +3524,6 @@ class nsContentUtils {
static nsIConsoleService* sConsoleService;
static nsTHashMap<nsRefPtrHashKey<nsAtom>, EventNameMapping>* sAtomEventTable;
static nsTHashMap<nsStringHashKey, EventNameMapping>* sStringEventTable;
static nsTArray<RefPtr<nsAtom>>* sUserDefinedEvents;
static nsIStringBundleService* sStringBundleService;
class nsContentUtilsReporter;

View File

@ -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<nsRefPtrHashKey<nsAtom>, int32_t> mURIToIDTable;
nsTHashMap<nsRefPtrHashKey<nsAtom>, int32_t> mDisabledURIToIDTable;
nsTHashMap<RefPtr<nsAtom>, int32_t> mURIToIDTable;
nsTHashMap<RefPtr<nsAtom>, int32_t> mDisabledURIToIDTable;
nsTArray<RefPtr<nsAtom>> mURIArray;
static mozilla::StaticRefPtr<nsNameSpaceManager> sInstance;

View File

@ -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<nsRefPtrHashKey<nsAtom>, nsAtom> mHyphAliases;
nsInterfaceHashtable<nsRefPtrHashKey<nsAtom>, nsIURI> mPatternFiles;
nsRefPtrHashtable<nsRefPtrHashKey<nsAtom>, nsHyphenator> mHyphenators;
nsRefPtrHashtable<nsAtomHashKey, nsAtom> mHyphAliases;
nsInterfaceHashtable<nsAtomHashKey, nsIURI> mPatternFiles;
nsRefPtrHashtable<nsAtomHashKey, nsHyphenator> mHyphenators;
static nsHyphenationManager* sInstance;
};

View File

@ -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<nsRefPtrHashKey<nsAtom>, nsStaticAtom*> mLangToGroup;
nsTHashMap<RefPtr<nsAtom>, nsStaticAtom*> mLangToGroup;
RefPtr<nsAtom> mLocaleLanguage;
};

View File

@ -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<nsPtrHashKey<nsIContent>, ContainStyleScope> mScopes;
nsTHashSet<nsRefPtrHashKey<nsAtom>> mDirtyCounters;
nsTHashSet<RefPtr<nsAtom>> mDirtyCounters;
};
} // namespace mozilla

View File

@ -344,7 +344,7 @@ class nsCounterManager {
private:
mozilla::ContainStyleScope* mScope;
nsClassHashtable<nsRefPtrHashKey<nsAtom>, nsCounterList> mNames;
nsClassHashtable<nsAtomHashKey, nsCounterList> mNames;
};
#endif /* nsCounterManager_h_ */

View File

@ -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<nsAtom> 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<AtomKey, NamedArea, AtomKey>;
using ImplicitNamedAreas =
mozilla::HashMap<mozilla::AtomHashKey, NamedArea, mozilla::AtomHashKey>;
NS_DECLARE_FRAME_PROPERTY_DELETABLE(ImplicitNamedAreasProperty,
ImplicitNamedAreas)
ImplicitNamedAreas* GetImplicitNamedAreas() const {

View File

@ -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<ComputedStyle> mSelectionPseudoStyle;
nsTHashMap<RefPtr<const nsAtom>, RefPtr<ComputedStyle>>
nsTHashMap<RefPtr<nsAtom>, RefPtr<ComputedStyle>>
mCustomHighlightPseudoStyles;
// Common data

View File

@ -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<nsRefPtrHashKey<nsAtom>, CounterStyle*> mStyles;
nsTHashMap<RefPtr<nsAtom>, CounterStyle*> mStyles;
nsTArray<CounterStyle*> mRetiredStyles;
};

View File

@ -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<Pair<>> or something.
nsClassHashtable<nsRefPtrHashKey<nsAtom>, PartList> mMappings;
nsRefPtrHashtable<nsRefPtrHashKey<nsAtom>, nsAtom> mReverseMappings;
nsClassHashtable<nsAtomHashKey, PartList> mMappings;
nsRefPtrHashtable<nsAtomHashKey, nsAtom> mReverseMappings;
};
} // namespace mozilla

View File

@ -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<TimelineCollection<TimelineType>> {
public:
using SelfType = TimelineCollection<TimelineType>;
using TimelineMap =
nsTHashMap<nsRefPtrHashKey<const nsAtom>, RefPtr<TimelineType>>;
using TimelineMap = nsTHashMap<RefPtr<nsAtom>, RefPtr<TimelineType>>;
TimelineCollection(dom::Element& aElement, PseudoStyleType aPseudoType)
: mElement(aElement), mPseudo(aPseudoType) {
@ -38,11 +38,11 @@ class TimelineCollection final
~TimelineCollection();
already_AddRefed<TimelineType> Lookup(const nsAtom* aName) const {
already_AddRefed<TimelineType> Lookup(nsAtom* aName) const {
return mTimelines.Get(aName).forget();
}
already_AddRefed<TimelineType> Extract(const nsAtom* aName) {
already_AddRefed<TimelineType> Extract(nsAtom* aName) {
Maybe<RefPtr<TimelineType>> timeline = mTimelines.Extract(aName);
return timeline ? timeline->forget() : nullptr;
}

View File

@ -70,7 +70,7 @@ void TimelineManager::UpdateTimelines(Element* aElement,
template <typename TimelineType>
static already_AddRefed<TimelineType> PopExistingTimeline(
const nsAtom* aName, TimelineCollection<TimelineType>* aCollection) {
nsAtom* aName, TimelineCollection<TimelineType>* aCollection) {
if (!aCollection) {
return nullptr;
}

View File

@ -211,7 +211,7 @@ static void UpdateOldAnimationPropertiesWithNew(
static already_AddRefed<dom::AnimationTimeline> 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 elements descendants
@ -259,7 +259,7 @@ static already_AddRefed<dom::AnimationTimeline> 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)

View File

@ -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; }

View File

@ -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<nsStringHashKey, nsHTMLTag>;
using TagAtomHash = nsTHashMap<nsPtrHashKey<nsAtom>, nsHTMLTag>;
// Can be weak, because we know these are always static, see AddRefTable.
using TagAtomHash = nsTHashMap<nsAtom*, nsHTMLTag>;
static nsresult AddRefTable(void);
static void ReleaseTable(void);

View File

@ -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<extensions::WebExtensionPolicyCore> 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<nsPtrHashKey<const nsAtom>, WebExtensionPolicy> mExtensions;
// The WebExtensionPolicy object keeps the key alive.
nsRefPtrHashtable<nsWeakAtomHashKey, WebExtensionPolicy> mExtensions;
nsRefPtrHashtable<nsPtrHashKey<const extensions::DocumentObserver>,
extensions::DocumentObserver>

View File

@ -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<nsPtrHashKey<const nsAtom>, nsIRemoteTab> mAddonEntries;
nsInterfaceHashtable<nsAtomHashKey, nsIRemoteTab> 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.

View File

@ -46,6 +46,7 @@ EXPORTS += [
"nsArrayEnumerator.h",
"nsArrayUtils.h",
"nsAtom.h",
"nsAtomHashKeys.h",
"nsBaseHashtable.h",
"nsCharSeparatedTokenizer.h",
"nsCheapSets.h",

51
xpcom/ds/nsAtomHashKeys.h Normal file
View File

@ -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<nsAtom> {
using nsRefPtrHashKey::nsRefPtrHashKey;
static PLDHashNumber HashKey(KeyTypePointer aKey) {
return MOZ_LIKELY(aKey) ? aKey->hash() : 0;
}
};
struct nsWeakAtomHashKey : public nsPtrHashKey<nsAtom> {
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<nsAtom> 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

View File

@ -13,6 +13,7 @@
#include "nsBaseHashtable.h"
#include "nsCOMPtr.h"
#include "nsHashKeys.h"
#include "nsAtomHashKeys.h"
#include "nsHashtablesFwd.h"
#include <type_traits>
@ -29,6 +30,11 @@ struct nsKeyClass<KeyType*> {
using type = nsPtrHashKey<KeyType>;
};
template <>
struct nsKeyClass<nsAtom*> {
using type = nsWeakAtomHashKey;
};
template <>
struct nsKeyClass<nsCString> {
using type = nsCStringHashKey;
@ -57,6 +63,11 @@ struct nsKeyClass<RefPtr<T>> {
using type = nsRefPtrHashKey<T>;
};
template <>
struct nsKeyClass<RefPtr<nsAtom>> {
using type = nsAtomHashKey;
};
template <>
struct nsKeyClass<nsID> {
using type = nsIDHashKey;