Bug 1276669 - Part 3: Split out nsHTMLTags atom initialization. r=hsivonen, a=ritu
authorNathan Froyd <froydnj@mozilla.com>
Thu, 26 Jan 2017 15:43:39 -0500
changeset 358844 c922a29ad1460b52ee197a8a285006aba1076996
parent 358843 9feaa1d4b820f808154e306588b0cdfe6622c952
child 358845 a5abb9c78e53ff6083c4e81cad93416b2492c8e9
push id10663
push userryanvm@gmail.com
push dateWed, 01 Feb 2017 23:07:38 +0000
treeherdermozilla-aurora@b4ed5ea97d25 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewershsivonen, ritu
bugs1276669
milestone53.0a2
Bug 1276669 - Part 3: Split out nsHTMLTags atom initialization. r=hsivonen, a=ritu We do this for much the same reason that we moved the nsHtml5Atoms initialization. Otherwise, the nsHTMLTags atoms are lazily initialized long after we've sealed the static atom table in nsLayoutStatics.
layout/build/nsLayoutStatics.cpp
parser/htmlparser/nsHTMLTags.cpp
parser/htmlparser/nsHTMLTags.h
--- a/layout/build/nsLayoutStatics.cpp
+++ b/layout/build/nsLayoutStatics.cpp
@@ -47,16 +47,17 @@
 #include "nsTextFrame.h"
 #include "nsCCUncollectableMarker.h"
 #include "nsTextFragment.h"
 #include "nsCSSRuleProcessor.h"
 #include "nsCORSListenerProxy.h"
 #include "nsHTMLDNSPrefetch.h"
 #include "nsHtml5Atoms.h"
 #include "nsHtml5Module.h"
+#include "nsHTMLTags.h"
 #include "mozilla/dom/FallbackEncoding.h"
 #include "nsFocusManager.h"
 #include "nsListControlFrame.h"
 #include "mozilla/dom/HTMLInputElement.h"
 #include "SVGElementFactory.h"
 #include "nsSVGUtils.h"
 #include "nsMathMLAtoms.h"
 #include "nsMathMLOperators.h"
@@ -157,16 +158,17 @@ nsLayoutStatics::Initialize()
   nsCSSPseudoClasses::AddRefAtoms();
   nsCSSPseudoElements::AddRefAtoms();
   nsCSSKeywords::AddRefTable();
   nsCSSProps::AddRefTable();
   nsColorNames::AddRefTable();
   nsGkAtoms::AddRefAtoms();
   nsHtml5Atoms::AddRefAtoms();
   nsTextServicesDocument::RegisterAtoms();
+  nsHTMLTags::RegisterAtoms();
 
   StartupJSEnvironment();
   rv = nsRegion::InitStatic();
   if (NS_FAILED(rv)) {
     NS_ERROR("Could not initialize nsRegion");
     return rv;
   }
 
--- a/parser/htmlparser/nsHTMLTags.cpp
+++ b/parser/htmlparser/nsHTMLTags.cpp
@@ -51,41 +51,74 @@ HTMLTagsKeyCompareUCPtr(const void *key1
 static PLHashNumber
 HTMLTagsHashCodeAtom(const void *key)
 {
   return NS_PTR_TO_INT32(key) >> 2;
 }
 
 #define NS_HTMLTAG_NAME_MAX_LENGTH 10
 
+// static
+void
+nsHTMLTags::RegisterAtoms(void)
+{
 #define HTML_TAG(_tag, _classname, _interfacename) NS_STATIC_ATOM_BUFFER(Atombuffer_##_tag, #_tag)
 #define HTML_OTHER(_tag)
 #include "nsHTMLTagList.h"
 #undef HTML_TAG
 #undef HTML_OTHER
 
-
-// static
-nsresult
-nsHTMLTags::AddRefTable(void)
-{
-  // static array of tag StaticAtom structs
+// static array of tag StaticAtom structs
 #define HTML_TAG(_tag, _classname, _interfacename) NS_STATIC_ATOM(Atombuffer_##_tag, &nsHTMLTags::sTagAtomTable[eHTMLTag_##_tag - 1]),
 #define HTML_OTHER(_tag)
   static const nsStaticAtom sTagAtoms_info[] = {
 #include "nsHTMLTagList.h"
   };
 #undef HTML_TAG
 #undef HTML_OTHER
 
-  if (gTableRefCount++ == 0) {
-    // Fill in our static atom pointers
-    NS_RegisterStaticAtoms(sTagAtoms_info);
+  // Fill in our static atom pointers
+  NS_RegisterStaticAtoms(sTagAtoms_info);
 
 
+#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*)sTagAtoms_info[i].mStringBuffer->Data());
+      nsAutoString temp2((char16_t*)sTagAtoms_info[i].mStringBuffer->Data());
+      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(sTagUnicodeTable[i]);
+      nsAutoString temp2((char16_t*)sTagAtoms_info[i].mStringBuffer->Data());
+      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(sTagUnicodeTable[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)
+{
+  if (gTableRefCount++ == 0) {
     NS_ASSERTION(!gTagTable && !gTagAtomTable, "pre existing hash!");
 
     gTagTable = PL_NewHashTable(64, HTMLTagsHashCodeUCPtr,
                                 HTMLTagsKeyCompareUCPtr, PL_CompareValues,
                                 nullptr, nullptr);
     NS_ENSURE_TRUE(gTagTable, NS_ERROR_OUT_OF_MEMORY);
 
     gTagAtomTable = PL_NewHashTable(64, HTMLTagsHashCodeAtom,
@@ -100,47 +133,16 @@ nsHTMLTags::AddRefTable(void)
     int32_t i;
     for (i = 0; i < NS_HTML_TAG_MAX; ++i) {
       PL_HashTableAdd(gTagTable, sTagUnicodeTable[i],
                       NS_INT32_TO_PTR(i + 1));
 
       PL_HashTableAdd(gTagAtomTable, sTagAtomTable[i],
                       NS_INT32_TO_PTR(i + 1));
     }
-
-
-
-#if defined(DEBUG)
-    {
-      // let's verify that all names in the the table are lowercase...
-      for (i = 0; i < NS_HTML_TAG_MAX; ++i) {
-        nsAutoString temp1((char16_t*)sTagAtoms_info[i].mStringBuffer->Data());
-        nsAutoString temp2((char16_t*)sTagAtoms_info[i].mStringBuffer->Data());
-        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 (i = 0; i < NS_HTML_TAG_MAX; ++i) {
-        nsAutoString temp1(sTagUnicodeTable[i]);
-        nsAutoString temp2((char16_t*)sTagAtoms_info[i].mStringBuffer->Data());
-        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 (i = 0; i < NS_HTML_TAG_MAX; ++i) {
-        uint32_t len = NS_strlen(sTagUnicodeTable[i]);
-        maxTagNameLength = std::max(len, maxTagNameLength);        
-      }
-      NS_ASSERTION(maxTagNameLength == NS_HTMLTAG_NAME_MAX_LENGTH,
-                   "NS_HTMLTAG_NAME_MAX_LENGTH not set correctly!");
-    }
-#endif
   }
 
   return NS_OK;
 }
 
 // static
 void
 nsHTMLTags::ReleaseTable(void)
--- a/parser/htmlparser/nsHTMLTags.h
+++ b/parser/htmlparser/nsHTMLTags.h
@@ -36,16 +36,17 @@ enum nsHTMLTag {
 #undef HTML_TAG
 #undef HTML_OTHER
 
 // All tags before eHTMLTag_text are HTML tags
 #define NS_HTML_TAG_MAX int32_t(eHTMLTag_text - 1)
 
 class nsHTMLTags {
 public:
+  static void RegisterAtoms(void);
   static nsresult AddRefTable(void);
   static void ReleaseTable(void);
 
   // Functions for converting string or atom to id
   static nsHTMLTag LookupTag(const nsAString& aTagName);
   static nsHTMLTag CaseSensitiveLookupTag(const char16_t* aTagName)
   {
     NS_ASSERTION(gTagTable, "no lookup table, needs addref");