Bug 1411893 - Introduce nsStaticAtom. r=emilio,froydnj.

It's a sub-class of nsAtom, useful for cases where you know you are dealing
exclusively with static atoms. The nice thing about it is that you can use
raw nsStaticAtom pointers instead of RefPtr<>. (In fact, the AddRef/Release
implementations ensure that we'll crash if we use RefPtr<nsStaticAtom>.)

MozReview-Commit-ID: 4Q6QHX5h44V

--HG--
extra : rebase_source : e4237f85b4821b684db0ef84d1f9c5e17cdee428
This commit is contained in:
Nicholas Nethercote 2017-10-27 10:31:13 +11:00
Родитель 2c0771b514
Коммит 8ad99dd7fa
32 изменённых файлов: 122 добавлений и 100 удалений

Просмотреть файл

@ -1230,7 +1230,7 @@ static const EStateRule sWAIUnivStateMap[] = {
struct AttrCharacteristics
{
nsAtom** attributeName;
nsStaticAtom** attributeName;
const uint8_t characteristics;
};

Просмотреть файл

@ -156,7 +156,7 @@ struct nsRoleMapEntry
{ return nsDependentAtomString(*roleAtom); }
// ARIA role: string representation such as "button"
nsAtom** roleAtom;
nsStaticAtom** roleAtom;
// Role mapping rule: maps to enum Role
mozilla::a11y::role role;

Просмотреть файл

@ -20,11 +20,11 @@ using namespace mozilla::a11y::aria;
struct EnumTypeData
{
// ARIA attribute name.
nsAtom* const mAttrName;
nsStaticAtom* const mAttrName;
// States if the attribute value is matched to the enum value. Used as
// nsIContent::AttrValuesArray, last item must be nullptr.
nsAtom* const* const mValues[4];
nsStaticAtom* const* const mValues[4];
// States applied if corresponding enum values are matched.
const uint64_t mStates[3];

Просмотреть файл

@ -53,15 +53,15 @@ xpcAccessibleApplication* XPCApplicationAcc();
typedef Accessible* (New_Accessible)(nsIContent* aContent, Accessible* aContext);
struct MarkupAttrInfo {
nsAtom** name;
nsAtom** value;
nsStaticAtom** name;
nsStaticAtom** value;
nsAtom** DOMAttrName;
nsAtom** DOMAttrValue;
nsStaticAtom** DOMAttrName;
nsStaticAtom** DOMAttrValue;
};
struct MarkupMapInfo {
nsAtom** tag;
nsStaticAtom** tag;
New_Accessible* new_func;
a11y::role role;
MarkupAttrInfo attrs[4];

Просмотреть файл

@ -62,7 +62,7 @@ using namespace mozilla::a11y;
////////////////////////////////////////////////////////////////////////////////
// Static member initialization
static nsAtom** kRelationAttrs[] =
static nsStaticAtom** kRelationAttrs[] =
{
&nsGkAtoms::aria_labelledby,
&nsGkAtoms::aria_describedby,

Просмотреть файл

@ -3420,7 +3420,7 @@ nsDOMTokenListPropertyDestructor(void *aObject, nsAtom *aProperty,
NS_RELEASE(list);
}
static nsAtom** sPropertiesToTraverseAndUnlink[] =
static nsStaticAtom** sPropertiesToTraverseAndUnlink[] =
{
&nsGkAtoms::sandbox,
&nsGkAtoms::sizes,
@ -3429,7 +3429,7 @@ static nsAtom** sPropertiesToTraverseAndUnlink[] =
};
// static
nsAtom***
nsStaticAtom***
Element::HTMLSVGPropertiesToTraverseAndUnlink()
{
return sPropertiesToTraverseAndUnlink;
@ -3440,8 +3440,7 @@ Element::GetTokenList(nsAtom* aAtom,
const DOMTokenListSupportedTokenArray aSupportedTokens)
{
#ifdef DEBUG
nsAtom*** props =
HTMLSVGPropertiesToTraverseAndUnlink();
nsStaticAtom*** props = HTMLSVGPropertiesToTraverseAndUnlink();
bool found = false;
for (uint32_t i = 0; props[i]; ++i) {
if (*props[i] == aAtom) {

Просмотреть файл

@ -810,7 +810,7 @@ public:
* Attribute Mapping Helpers
*/
struct MappedAttributeEntry {
nsAtom** attribute;
nsStaticAtom** attribute;
};
/**
@ -827,7 +827,7 @@ public:
return FindAttributeDependence(aAttribute, aMaps, N);
}
static nsAtom*** HTMLSVGPropertiesToTraverseAndUnlink();
static nsStaticAtom*** HTMLSVGPropertiesToTraverseAndUnlink();
private:
void DescribeAttribute(uint32_t index, nsAString& aOutDescription) const;

Просмотреть файл

@ -1470,7 +1470,7 @@ NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(FragmentOrElement)
}
if (tmp->IsHTMLElement() || tmp->IsSVGElement()) {
nsAtom*** props = Element::HTMLSVGPropertiesToTraverseAndUnlink();
nsStaticAtom*** props = Element::HTMLSVGPropertiesToTraverseAndUnlink();
for (uint32_t i = 0; props[i]; ++i) {
tmp->DeleteProperty(*props[i]);
}
@ -2057,7 +2057,7 @@ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INTERNAL(FragmentOrElement)
}
}
if (tmp->IsHTMLElement() || tmp->IsSVGElement()) {
nsAtom*** props = Element::HTMLSVGPropertiesToTraverseAndUnlink();
nsStaticAtom*** props = Element::HTMLSVGPropertiesToTraverseAndUnlink();
for (uint32_t i = 0; props[i]; ++i) {
nsISupports* property =
static_cast<nsISupports*>(tmp->GetProperty(*props[i]));

Просмотреть файл

@ -483,7 +483,7 @@ public:
* @return ATTR_MISSING, ATTR_VALUE_NO_MATCH or the non-negative index
* indicating the first value of aValues that matched
*/
typedef nsAtom* const* const AttrValuesArray;
typedef nsStaticAtom* const* const AttrValuesArray;
virtual int32_t FindAttrValueIn(int32_t aNameSpaceID,
nsAtom* aName,
AttrValuesArray* aValues,

Просмотреть файл

@ -32,7 +32,7 @@ using namespace mozilla;
//
// Thanks to Mark Pilgrim and Sam Ruby for the initial whitelist
//
nsAtom** const kElementsHTML[] = {
nsStaticAtom** const kElementsHTML[] = {
&nsGkAtoms::a,
&nsGkAtoms::abbr,
&nsGkAtoms::acronym,
@ -147,7 +147,7 @@ nsAtom** const kElementsHTML[] = {
nullptr
};
nsAtom** const kAttributesHTML[] = {
nsStaticAtom** const kAttributesHTML[] = {
&nsGkAtoms::abbr,
&nsGkAtoms::accept,
&nsGkAtoms::acceptcharset,
@ -253,7 +253,7 @@ nsAtom** const kAttributesHTML[] = {
nullptr
};
nsAtom** const kPresAttributesHTML[] = {
nsStaticAtom** const kPresAttributesHTML[] = {
&nsGkAtoms::align,
&nsGkAtoms::background,
&nsGkAtoms::bgcolor,
@ -272,7 +272,7 @@ nsAtom** const kPresAttributesHTML[] = {
nullptr
};
nsAtom** const kURLAttributesHTML[] = {
nsStaticAtom** const kURLAttributesHTML[] = {
&nsGkAtoms::action,
&nsGkAtoms::href,
&nsGkAtoms::src,
@ -282,7 +282,7 @@ nsAtom** const kURLAttributesHTML[] = {
nullptr
};
nsAtom** const kElementsSVG[] = {
nsStaticAtom** const kElementsSVG[] = {
&nsGkAtoms::a, // a
&nsGkAtoms::circle, // circle
&nsGkAtoms::clipPath, // clipPath
@ -362,7 +362,7 @@ nsAtom** const kElementsSVG[] = {
nullptr
};
nsAtom** const kAttributesSVG[] = {
nsStaticAtom** const kAttributesSVG[] = {
// accent-height
&nsGkAtoms::accumulate, // accumulate
&nsGkAtoms::additive, // additive
@ -595,12 +595,12 @@ nsAtom** const kAttributesSVG[] = {
nullptr
};
nsAtom** const kURLAttributesSVG[] = {
nsStaticAtom** const kURLAttributesSVG[] = {
&nsGkAtoms::href,
nullptr
};
nsAtom** const kElementsMathML[] = {
nsStaticAtom** const kElementsMathML[] = {
&nsGkAtoms::abs_, // abs
&nsGkAtoms::_and, // and
&nsGkAtoms::annotation_, // annotation
@ -799,7 +799,7 @@ nsAtom** const kElementsMathML[] = {
nullptr
};
nsAtom** const kAttributesMathML[] = {
nsStaticAtom** const kAttributesMathML[] = {
&nsGkAtoms::accent_, // accent
&nsGkAtoms::accentunder_, // accentunder
&nsGkAtoms::actiontype_, // actiontype
@ -917,7 +917,7 @@ nsAtom** const kAttributesMathML[] = {
nullptr
};
nsAtom** const kURLAttributesMathML[] = {
nsStaticAtom** const kURLAttributesMathML[] = {
&nsGkAtoms::href,
&nsGkAtoms::src,
&nsGkAtoms::cdgroup_,
@ -995,9 +995,9 @@ nsTreeSanitizer::MustFlatten(int32_t aNamespace, nsAtom* aLocal)
}
bool
nsTreeSanitizer::IsURL(nsAtom** const* aURLs, nsAtom* aLocalName)
nsTreeSanitizer::IsURL(nsStaticAtom** const* aURLs, nsAtom* aLocalName)
{
nsAtom** atomPtrPtr;
nsStaticAtom** atomPtrPtr;
while ((atomPtrPtr = *aURLs)) {
if (*atomPtrPtr == aLocalName) {
return true;
@ -1163,7 +1163,7 @@ nsTreeSanitizer::SanitizeStyleSheet(const nsAString& aOriginal,
void
nsTreeSanitizer::SanitizeAttributes(mozilla::dom::Element* aElement,
nsTHashtable<nsRefPtrHashKey<nsAtom>>* aAllowed,
nsAtom** const* aURLs,
nsStaticAtom** const* aURLs,
bool aAllowXLink,
bool aAllowStyle,
bool aAllowDangerousSrc)

Просмотреть файл

@ -113,7 +113,7 @@ class MOZ_STACK_CLASS nsTreeSanitizer {
* @param aLocalName the name to search on the list
* @return true if aLocalName is on the aURLs list and false otherwise
*/
bool IsURL(nsAtom** const* aURLs, nsAtom* aLocalName);
bool IsURL(nsStaticAtom** const* aURLs, nsAtom* aLocalName);
/**
* Removes dangerous attributes from the element. If the style attribute
@ -131,7 +131,7 @@ class MOZ_STACK_CLASS nsTreeSanitizer {
*/
void SanitizeAttributes(mozilla::dom::Element* aElement,
nsTHashtable<nsRefPtrHashKey<nsAtom>>* aAllowed,
nsAtom** const* aURLs,
nsStaticAtom** const* aURLs,
bool aAllowXLink,
bool aAllowStyle,
bool aAllowDangerousSrc);

Просмотреть файл

@ -184,7 +184,7 @@ SVGLength::GetUserUnitsPerPercent(const nsSVGElement *aElement, uint8_t aAxis)
// Helpers:
// These items must be at the same index as the nsIDOMSVGLength constants!
static nsAtom** const unitMap[] =
static nsStaticAtom** const unitMap[] =
{
nullptr, /* SVG_LENGTHTYPE_UNKNOWN */
nullptr, /* SVG_LENGTHTYPE_NUMBER */

Просмотреть файл

@ -15,7 +15,7 @@
namespace mozilla {
namespace dom {
nsAtom** SVGTests::sStringListNames[3] =
nsStaticAtom** SVGTests::sStringListNames[3] =
{
&nsGkAtoms::requiredFeatures,
&nsGkAtoms::requiredExtensions,

Просмотреть файл

@ -13,6 +13,7 @@
class nsAttrValue;
class nsAtom;
class nsStaticAtom;
namespace mozilla {
class DOMSVGStringList;
@ -102,7 +103,7 @@ protected:
private:
enum { FEATURES, EXTENSIONS, LANGUAGE };
SVGStringList mStringListAttributes[3];
static nsAtom** sStringListNames[3];
static nsStaticAtom** sStringListNames[3];
};
NS_DEFINE_STATIC_IID_ACCESSOR(SVGTests, MOZILLA_DOMSVGTESTS_IID)

Просмотреть файл

@ -68,7 +68,7 @@ SVGTransformListParser::ParseTransform()
}
const nsAString& transform = Substring(start.get(), mIter.get());
nsAtom* keyAtom = NS_GetStaticAtom(transform);
nsStaticAtom* keyAtom = NS_GetStaticAtom(transform);
if (!keyAtom || !SkipWsp()) {
return false;

Просмотреть файл

@ -20,7 +20,7 @@
using namespace mozilla;
using namespace mozilla::dom;
static nsAtom** const unitMap[] =
static nsStaticAtom** const unitMap[] =
{
nullptr, /* SVG_ANGLETYPE_UNKNOWN */
nullptr, /* SVG_ANGLETYPE_UNSPECIFIED */
@ -67,7 +67,7 @@ GetUnitTypeForString(const nsAString& unitStr)
if (unitStr.IsEmpty())
return SVG_ANGLETYPE_UNSPECIFIED;
nsAtom *unitAtom = NS_GetStaticAtom(unitStr);
nsStaticAtom* unitAtom = NS_GetStaticAtom(unitStr);
if (unitAtom) {
for (uint32_t i = 0 ; i < ArrayLength(unitMap) ; i++) {

Просмотреть файл

@ -370,7 +370,7 @@ protected:
static nsAtom* GetEventNameForAttr(nsAtom* aAttr);
struct LengthInfo {
nsAtom** mName;
nsStaticAtom** mName;
float mDefaultValue;
uint8_t mDefaultUnitType;
uint8_t mCtxType;
@ -391,7 +391,7 @@ protected:
};
struct NumberInfo {
nsAtom** mName;
nsStaticAtom** mName;
float mDefaultValue;
bool mPercentagesAllowed;
};
@ -411,7 +411,7 @@ protected:
};
struct NumberPairInfo {
nsAtom** mName;
nsStaticAtom** mName;
float mDefaultValue1;
float mDefaultValue2;
};
@ -432,7 +432,7 @@ protected:
};
struct IntegerInfo {
nsAtom** mName;
nsStaticAtom** mName;
int32_t mDefaultValue;
};
@ -451,7 +451,7 @@ protected:
};
struct IntegerPairInfo {
nsAtom** mName;
nsStaticAtom** mName;
int32_t mDefaultValue1;
int32_t mDefaultValue2;
};
@ -472,7 +472,7 @@ protected:
};
struct AngleInfo {
nsAtom** mName;
nsStaticAtom** mName;
float mDefaultValue;
uint8_t mDefaultUnitType;
};
@ -492,7 +492,7 @@ protected:
};
struct BooleanInfo {
nsAtom** mName;
nsStaticAtom** mName;
bool mDefaultValue;
};
@ -513,7 +513,7 @@ protected:
friend class nsSVGEnum;
struct EnumInfo {
nsAtom** mName;
nsStaticAtom** mName;
nsSVGEnumMapping* mMapping;
uint16_t mDefaultValue;
};
@ -533,7 +533,7 @@ protected:
};
struct NumberListInfo {
nsAtom** mName;
nsStaticAtom** mName;
};
struct NumberListAttributesInfo {
@ -553,7 +553,7 @@ protected:
};
struct LengthListInfo {
nsAtom** mName;
nsStaticAtom** mName;
uint8_t mAxis;
/**
* Flag to indicate whether appending zeros to the end of the list would
@ -583,7 +583,7 @@ protected:
};
struct StringInfo {
nsAtom** mName;
nsStaticAtom** mName;
int32_t mNamespaceID;
bool mIsAnimatable;
};
@ -605,7 +605,7 @@ protected:
friend class mozilla::DOMSVGStringList;
struct StringListInfo {
nsAtom** mName;
nsStaticAtom** mName;
};
struct StringListAttributesInfo {

Просмотреть файл

@ -27,7 +27,7 @@ class SVGAnimationElement;
typedef uint8_t nsSVGEnumValue;
struct nsSVGEnumMapping {
nsAtom **mKey;
nsStaticAtom** mKey;
nsSVGEnumValue mVal;
};

Просмотреть файл

@ -22,7 +22,7 @@
using namespace mozilla;
using namespace mozilla::dom;
static nsAtom** const unitMap[] =
static nsStaticAtom** const unitMap[] =
{
nullptr, /* SVG_LENGTHTYPE_UNKNOWN */
nullptr, /* SVG_LENGTHTYPE_NUMBER */

Просмотреть файл

@ -24,7 +24,7 @@ struct txCoreFunctionDescriptor
int8_t mMinParams;
int8_t mMaxParams;
Expr::ResultType mReturnType;
nsAtom** mName;
nsStaticAtom** mName;
};
// This must be ordered in the same order as txCoreFunctionCall::eType.

Просмотреть файл

@ -169,7 +169,7 @@ struct txEXSLTFunctionDescriptor
int8_t mMaxParams;
Expr::ResultType mReturnType;
int32_t mNamespaceID;
nsAtom** mName;
nsStaticAtom** mName;
const char* mNamespaceURI;
};

Просмотреть файл

@ -289,8 +289,6 @@ protected:
// pseudo constants
static int32_t gRefCnt;
static nsAtom** kIdentityAttrs[];
static nsIRDFService* gRDFService;
static nsIRDFResource* kNC_persist;
static nsIRDFResource* kNC_attribute;

Просмотреть файл

@ -781,9 +781,9 @@ private:
stored somewhere that this struct can point to (that is, a static
nsAtom*) and that it's allocated before the struct is ever used. */
struct FrameConstructionDataByTag {
// Pointer to nsAtom* is used because we want to initialize this
// Pointer to nsStaticAtom* is used because we want to initialize this
// statically, so before our atom tables are set up.
const nsAtom * const * const mTag;
const nsStaticAtom * const * const mTag;
const FrameConstructionData mData;
};

Просмотреть файл

@ -575,13 +575,13 @@ SystemUsesNegativeSign(uint8_t aSystem)
class BuiltinCounterStyle : public CounterStyle
{
public:
constexpr BuiltinCounterStyle(int32_t aStyle, nsAtom** aName)
constexpr BuiltinCounterStyle(int32_t aStyle, nsStaticAtom** aName)
: CounterStyle(aStyle)
, mName(aName)
{
}
virtual nsAtom* GetStyleName() const final;
virtual nsStaticAtom* GetStyleName() const final;
virtual void GetPrefix(nsAString& aResult) override;
virtual void GetSuffix(nsAString& aResult) override;
virtual void GetSpokenCounterText(CounterValue aOrdinal,
@ -615,10 +615,10 @@ private:
// Extra indirection to point to nsGkAtoms members rather than the
// nsAtom, because members of nsGkAtoms are updated at runtime but
// we want to construct BuiltinCounterStyle at compile time.
nsAtom** const mName;
nsStaticAtom** const mName;
};
/* virtual */ nsAtom*
/* virtual */ nsStaticAtom*
BuiltinCounterStyle::GetStyleName() const
{
return *mName;

Просмотреть файл

@ -7959,7 +7959,8 @@ CSSParserImpl::ParseCounter(nsCSSValue& aValue)
break;
}
} else {
type.SetAtomIdentValue(do_AddRef(nsGkAtoms::decimal));
type.SetAtomIdentValue(
do_AddRef(static_cast<nsAtom*>(nsGkAtoms::decimal)));
}
if (!ExpectSymbol(')', true)) {

Просмотреть файл

@ -22,7 +22,7 @@ typedef void (*nsMediaFeatureValueGetter)(nsPresContext* aPresContext,
struct nsMediaFeature
{
nsAtom **mName; // extra indirection to point to nsGkAtoms members
nsStaticAtom** mName; // extra indirection to point to nsGkAtoms members
enum RangeType { eMinMaxAllowed, eMinMaxNotAllowed };
RangeType mRangeType;

Просмотреть файл

@ -50,7 +50,7 @@ nsHtml5AtomTable::GetAtom(const nsAString& aKey)
return cachedAtom;
}
nsAtom* atom = NS_GetStaticAtom(aKey);
nsStaticAtom* atom = NS_GetStaticAtom(aKey);
if (atom) {
mRecentlyUsedParserAtoms[index] = atom;
return atom;

Просмотреть файл

@ -53,7 +53,7 @@ HTMLTagsHashCodeAtom(const void *key)
#define NS_HTMLTAG_NAME_MAX_LENGTH 10
// This would use NS_STATIC_ATOM_DEFN if it wasn't an array.
nsAtom* nsHTMLTags::sTagAtomTable[eHTMLTag_userdefined - 1];
nsStaticAtom* nsHTMLTags::sTagAtomTable[eHTMLTag_userdefined - 1];
#define HTML_TAG(_tag, _classname, _interfacename) \
NS_STATIC_ATOM_BUFFER(_tag, #_tag)

Просмотреть файл

@ -76,7 +76,7 @@ public:
private:
// This would use NS_STATIC_ATOM_DECL if it wasn't an array.
static nsAtom* sTagAtomTable[eHTMLTag_userdefined - 1];
static nsStaticAtom* sTagAtomTable[eHTMLTag_userdefined - 1];
static const char16_t* const sTagUnicodeTable[];
static int32_t gTableRefCount;

Просмотреть файл

@ -11,9 +11,6 @@
#include "nsString.h"
#include "nsStringBuffer.h"
// This class would be |final| if it wasn't for nsICSSAnonBoxPseudo and
// nsICSSPseudoElement, which are trivial subclasses used to ensure only
// certain atoms are passed to certain functions.
class nsAtom
{
public:
@ -85,13 +82,14 @@ private:
friend class nsAtomFriend;
friend class nsHtml5AtomEntry;
// Construction and destruction is done entirely by |friend|s.
// Dynamic atom construction is done by |friend|s.
nsAtom(AtomKind aKind, const nsAString& aString, uint32_t aHash);
nsAtom(const char16_t* aString, uint32_t aLength, uint32_t aHash);
protected:
nsAtom(const char16_t* aString, uint32_t aLength, uint32_t aHash);
~nsAtom();
private:
mozilla::ThreadSafeAutoRefCnt mRefCnt;
uint32_t mLength: 30;
uint32_t mKind: 2; // nsAtom::AtomKind
@ -103,6 +101,30 @@ private:
char16_t* mString;
};
// A trivial subclass of nsAtom that can be used for known static atoms. The
// main advantage of this class is that it doesn't require refcounting, so you
// can use |nsStaticAtom*| in contrast with |RefPtr<nsAtom>|.
//
// This class would be |final| if it wasn't for nsICSSAnonBoxPseudo and
// nsICSSPseudoElement, which are trivial subclasses used to ensure only
// certain atoms are passed to certain functions.
class nsStaticAtom : public nsAtom
{
public:
// These are deleted so it's impossible to RefPtr<nsStaticAtom>. Raw
// nsStaticAtom atoms should be used instead.
MozExternalRefCountType AddRef() = delete;
MozExternalRefCountType Release() = delete;
private:
friend class nsAtomFriend;
// Construction is done entirely by |friend|s.
nsStaticAtom(const char16_t* aString, uint32_t aLength, uint32_t aHash)
: nsAtom(aString, aLength, aHash)
{}
};
// The four forms of NS_Atomize (for use with |RefPtr<nsAtom>|) return the
// atom for the string given. At any given time there will always be one atom
// representing a given string. Atoms are intended to make string comparison
@ -131,7 +153,7 @@ nsrefcnt NS_GetNumberOfAtoms();
// Return a pointer for a static atom for the string or null if there's no
// static atom for this string.
nsAtom* NS_GetStaticAtom(const nsAString& aUTF16String);
nsStaticAtom* NS_GetStaticAtom(const nsAString& aUTF16String);
// Seal the static atom table.
void NS_SealStaticAtomTable();

Просмотреть файл

@ -455,7 +455,7 @@ public:
// Static atoms aren't really refcounted. Because these entries live in a
// global hashtable, this reference is essentially owning.
nsAtom* MOZ_OWNING_REF mAtom;
nsStaticAtom* MOZ_OWNING_REF mAtom;
};
/**
@ -586,7 +586,7 @@ nsAtomFriend::RegisterStaticAtoms(const nsStaticAtomSetup* aSetup,
for (uint32_t i = 0; i < aCount; ++i) {
const char16_t* string = aSetup[i].mString;
nsAtom** atomp = aSetup[i].mAtom;
nsStaticAtom** atomp = aSetup[i].mAtom;
MOZ_ASSERT(nsCRT::IsAscii(string));
@ -595,20 +595,21 @@ nsAtomFriend::RegisterStaticAtoms(const nsStaticAtomSetup* aSetup,
uint32_t hash;
AtomTableEntry* he = GetAtomHashEntry(string, stringLen, &hash);
nsAtom* atom = he->mAtom;
if (atom) {
nsStaticAtom* atom;
if (he->mAtom) {
// Disallow creating a dynamic atom, and then later, while the
// dynamic atom is still alive, registering that same atom as a
// static atom. It causes subtle bugs, and we're programming in
// C++ here, not Smalltalk.
if (!atom->IsStaticAtom()) {
if (!he->mAtom->IsStaticAtom()) {
nsAutoCString name;
atom->ToUTF8String(name);
he->mAtom->ToUTF8String(name);
MOZ_CRASH_UNSAFE_PRINTF(
"Static atom registration for %s should be pushed back", name.get());
}
atom = static_cast<nsStaticAtom*>(he->mAtom);
} else {
atom = new nsAtom(string, stringLen, hash);
atom = new nsStaticAtom(string, stringLen, hash);
he->mAtom = atom;
}
*atomp = atom;
@ -757,7 +758,7 @@ NS_GetUnusedAtomCount(void)
return gUnusedAtomCount;
}
nsAtom*
nsStaticAtom*
NS_GetStaticAtom(const nsAString& aUTF16String)
{
NS_PRECONDITION(gStaticAtomTable, "Static atom table not created yet.");

Просмотреть файл

@ -9,7 +9,7 @@
#include <stdint.h>
class nsAtom;
class nsStaticAtom;
// The following macros are used to define static atoms, typically in
// conjunction with a .h file that defines the names and values of the atoms.
@ -48,14 +48,14 @@ class nsAtom;
// class MyAtoms
// {
// public:
// static nsAtom* one;
// static nsAtom* two;
// static nsAtom* three;
// static nsStaticAtom* one;
// static nsStaticAtom* two;
// static nsStaticAtom* three;
// };
//
// nsAtom* MyAtoms::one;
// nsAtom* MyAtoms::two;
// nsAtom* MyAtoms::three;
// nsStaticAtom* MyAtoms::one;
// nsStaticAtom* MyAtoms::two;
// nsStaticAtom* MyAtoms::three;
//
// static const char16_t one_buffer[4] = u"one"; // plus a static_assert
// static const char16_t two_buffer[4] = u"two"; // plus a static_assert
@ -69,24 +69,24 @@ class nsAtom;
//
// When RegisterStaticAtoms(sMyAtomSetup) is called it iterates over
// sMyAtomSetup[]. E.g. for the first atom it does roughly the following:
// - MyAtoms::one = new nsAtom(one_buffer)
// - MyAtoms::one = new nsStaticAtom(one_buffer)
// - inserts MyAtoms::one into the atom table
// The declaration of the pointer to the static atom, which must be within a
// class.
#define NS_STATIC_ATOM_DECL(name_) \
static nsAtom* name_;
static nsStaticAtom* name_;
// Like NS_STATIC_ATOM_DECL, but for sub-classes of nsAtom.
// Like NS_STATIC_ATOM_DECL, but for sub-classes of nsStaticAtom.
#define NS_STATIC_ATOM_SUBCLASS_DECL(type_, name_) \
static type_* name_;
// The definition of the pointer to the static atom. Initially null, it is
// set by RegisterStaticAtoms() to point to a heap-allocated nsAtom.
// set by RegisterStaticAtoms() to point to a heap-allocated nsStaticAtom.
#define NS_STATIC_ATOM_DEFN(class_, name_) \
nsAtom* class_::name_;
nsStaticAtom* class_::name_;
// Like NS_STATIC_ATOM_DEFN, but for sub-classes of nsAtom.
// Like NS_STATIC_ATOM_DEFN, but for sub-classes of nsStaticAtom.
#define NS_STATIC_ATOM_SUBCLASS_DEFN(type_, class_, name_) \
type_* class_::name_;
@ -103,9 +103,9 @@ class nsAtom;
#define NS_STATIC_ATOM_SETUP(class_, name_) \
{ name_##_buffer, &class_::name_ },
// Like NS_STATIC_ATOM_SUBCLASS, but for sub-classes of nsAtom.
// Like NS_STATIC_ATOM_SUBCLASS, but for sub-classes of nsStaticAtom.
#define NS_STATIC_ATOM_SUBCLASS_SETUP(class_, name_) \
{ name_##_buffer, reinterpret_cast<nsAtom**>(&class_::name_) },
{ name_##_buffer, reinterpret_cast<nsStaticAtom**>(&class_::name_) },
// Holds data used to initialize large number of atoms during startup. Use
// NS_STATIC_ATOM_SETUP to initialize these structs. They should never be
@ -113,7 +113,7 @@ class nsAtom;
struct nsStaticAtomSetup
{
const char16_t* const mString;
nsAtom** const mAtom;
nsStaticAtom** const mAtom;
};
// Register an array of static atoms with the atom table.