зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1445079 - Remove nsHTMLTags::sTagAtomTable[]. r=froydnj
The atoms in nsHTMLTags are a subset of nsGkAtoms, which means that sTagAtomTable[] currently ends up holding duplicate pointers to the same static atoms. This patch removes sTagAtomTable[]. The only place that used sTagAtomTable[] was nsHTMLTags::AddRefTable(). It now instead calls NS_GetStaticAtom() to get the static atoms registered by nsGkAtoms. The patch also moves some checking of sTagNames from RegisterAtoms() (which is removed) to AddRefTable(). All this reduces the number of duplicate static atoms from 148 to 12. MozReview-Commit-ID: 14qXYeoorFr * * * [mq]: foo MozReview-Commit-ID: AgQbXlcvWrt
This commit is contained in:
Родитель
d967055f0b
Коммит
991955fad8
|
@ -155,7 +155,6 @@ nsLayoutStatics::Initialize()
|
|||
nsCSSProps::AddRefTable();
|
||||
nsColorNames::AddRefTable();
|
||||
nsGkAtoms::AddRefAtoms();
|
||||
nsHTMLTags::RegisterAtoms();
|
||||
nsRDFAtoms::RegisterAtoms();
|
||||
|
||||
NS_SetStaticAtomsDone();
|
||||
|
|
|
@ -30,61 +30,6 @@ nsHTMLTags::TagAtomHash* nsHTMLTags::gTagAtomTable;
|
|||
|
||||
#define NS_HTMLTAG_NAME_MAX_LENGTH 10
|
||||
|
||||
// This would use NS_STATIC_ATOM_DEFN if it wasn't an array.
|
||||
nsStaticAtom* nsHTMLTags::sTagAtomTable[eHTMLTag_userdefined - 1];
|
||||
|
||||
#define HTML_TAG(_tag, _classname, _interfacename) \
|
||||
NS_STATIC_ATOM_BUFFER(_tag, #_tag)
|
||||
#define HTML_OTHER(_tag)
|
||||
#include "nsHTMLTagList.h"
|
||||
#undef HTML_TAG
|
||||
#undef HTML_OTHER
|
||||
|
||||
/* static */ void
|
||||
nsHTMLTags::RegisterAtoms(void)
|
||||
{
|
||||
// This would use NS_STATIC_ATOM_SETUP if it wasn't an array.
|
||||
static const nsStaticAtomSetup sTagAtomSetup[] = {
|
||||
#define HTML_TAG(_tag, _classname, _interfacename) \
|
||||
{ _tag##_buffer, &nsHTMLTags::sTagAtomTable[eHTMLTag_##_tag - 1] },
|
||||
#define HTML_OTHER(_tag)
|
||||
#include "nsHTMLTagList.h"
|
||||
#undef HTML_TAG
|
||||
#undef HTML_OTHER
|
||||
};
|
||||
|
||||
NS_RegisterStaticAtoms(sTagAtomSetup);
|
||||
|
||||
#if defined(DEBUG)
|
||||
{
|
||||
// let's verify that all names in the the table are lowercase...
|
||||
for (int32_t i = 0; i < NS_HTML_TAG_MAX; ++i) {
|
||||
nsAutoString temp1((char16_t*)sTagAtomSetup[i].mString);
|
||||
nsAutoString temp2((char16_t*)sTagAtomSetup[i].mString);
|
||||
ToLowerCase(temp1);
|
||||
NS_ASSERTION(temp1.Equals(temp2), "upper case char in table");
|
||||
}
|
||||
|
||||
// let's verify that all names in the unicode strings above are
|
||||
// correct.
|
||||
for (int32_t i = 0; i < NS_HTML_TAG_MAX; ++i) {
|
||||
nsAutoString temp1(sTagNames[i]);
|
||||
nsAutoString temp2((char16_t*)sTagAtomSetup[i].mString);
|
||||
NS_ASSERTION(temp1.Equals(temp2), "Bad unicode tag name!");
|
||||
}
|
||||
|
||||
// let's verify that NS_HTMLTAG_NAME_MAX_LENGTH is correct
|
||||
uint32_t maxTagNameLength = 0;
|
||||
for (int32_t i = 0; i < NS_HTML_TAG_MAX; ++i) {
|
||||
uint32_t len = NS_strlen(sTagNames[i]);
|
||||
maxTagNameLength = std::max(len, maxTagNameLength);
|
||||
}
|
||||
NS_ASSERTION(maxTagNameLength == NS_HTMLTAG_NAME_MAX_LENGTH,
|
||||
"NS_HTMLTAG_NAME_MAX_LENGTH not set correctly!");
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
// static
|
||||
nsresult
|
||||
nsHTMLTags::AddRefTable(void)
|
||||
|
@ -99,17 +44,39 @@ nsHTMLTags::AddRefTable(void)
|
|||
// keys and the value of the corresponding enum as the value in
|
||||
// the table.
|
||||
|
||||
int32_t i;
|
||||
for (i = 0; i < NS_HTML_TAG_MAX; ++i) {
|
||||
for (int32_t i = 0; i < NS_HTML_TAG_MAX; ++i) {
|
||||
const char16_t* tagName = sTagNames[i];
|
||||
const nsHTMLTag tagValue = static_cast<nsHTMLTag>(i + 1);
|
||||
|
||||
// We use AssignLiteral here to avoid a string copy. This is okay
|
||||
// because this is truly static data.
|
||||
nsString tmp;
|
||||
tmp.AssignLiteral(tagName, nsString::char_traits::length(tagName));
|
||||
gTagTable->Put(tmp, tagValue);
|
||||
gTagAtomTable->Put(sTagAtomTable[i], tagValue);
|
||||
|
||||
// All the HTML tag names are static atoms within nsGkAtoms, and they are
|
||||
// registered before this code is reached.
|
||||
nsStaticAtom* atom = NS_GetStaticAtom(tmp);
|
||||
MOZ_ASSERT(atom);
|
||||
gTagAtomTable->Put(atom, tagValue);
|
||||
}
|
||||
|
||||
#ifdef DEBUG
|
||||
// Check all tagNames are lowercase, and that NS_HTMLTAG_NAME_MAX_LENGTH is
|
||||
// correct.
|
||||
uint32_t maxTagNameLength = 0;
|
||||
for (int i = 0; i < NS_HTML_TAG_MAX; ++i) {
|
||||
const char16_t* tagName = sTagNames[i];
|
||||
|
||||
nsAutoString lowerTagName(tagName);
|
||||
ToLowerCase(lowerTagName);
|
||||
MOZ_ASSERT(lowerTagName.Equals(tagName));
|
||||
|
||||
maxTagNameLength = std::max(NS_strlen(tagName), maxTagNameLength);
|
||||
}
|
||||
|
||||
MOZ_ASSERT(maxTagNameLength == NS_HTMLTAG_NAME_MAX_LENGTH);
|
||||
#endif
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
|
|
|
@ -44,7 +44,6 @@ public:
|
|||
using TagStringHash = nsDataHashtable<nsStringHashKey, nsHTMLTag>;
|
||||
using TagAtomHash = nsDataHashtable<nsPtrHashKey<nsAtom>, nsHTMLTag>;
|
||||
|
||||
static void RegisterAtoms(void);
|
||||
static nsresult AddRefTable(void);
|
||||
static void ReleaseTable(void);
|
||||
|
||||
|
@ -76,8 +75,6 @@ public:
|
|||
#endif
|
||||
|
||||
private:
|
||||
// This would use NS_STATIC_ATOM_DECL if it wasn't an array.
|
||||
static nsStaticAtom* sTagAtomTable[eHTMLTag_userdefined - 1];
|
||||
static const char16_t* const sTagNames[];
|
||||
|
||||
static int32_t gTableRefCount;
|
||||
|
|
Загрузка…
Ссылка в новой задаче