Bug 1664312 - Reorder ParserAtomsTable methods r=djvj
authorTed Campbell <tcampbell@mozilla.com>
Wed, 16 Sep 2020 18:30:09 +0000
changeset 548968 36a190a3d381a91fd42bf5fea3c1f09ca5e061db
parent 548967 b8e17781c000be1bcec132ae37457589de2f87af
child 548969 13ace5d469df6d56a2028600f65c24ad80488934
push id37790
push userbtara@mozilla.com
push dateThu, 17 Sep 2020 10:09:40 +0000
treeherdermozilla-central@5f3283738794 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdjvj
bugs1664312
milestone82.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1664312 - Reorder ParserAtomsTable methods r=djvj Depends on D90149 Differential Revision: https://phabricator.services.mozilla.com/D90150
js/src/frontend/ParserAtom.cpp
js/src/frontend/ParserAtom.h
--- a/js/src/frontend/ParserAtom.cpp
+++ b/js/src/frontend/ParserAtom.cpp
@@ -182,28 +182,40 @@ void ParserAtomEntry::dumpCharsNoQuote(j
     JSString::dumpCharsNoQuote<char16_t>(twoByteChars(), length(), out);
   }
 }
 #endif
 
 ParserAtomsTable::ParserAtomsTable(JSRuntime* rt)
     : wellKnownTable_(*rt->commonParserNames) {}
 
+template <typename CharT>
+ParserAtomsTable::AddPtr ParserAtomsTable::lookupForAdd(
+    JSContext* cx, InflatedChar16Sequence<CharT> seq) {
+  // Check against well-known.
+  SpecificParserAtomLookup<CharT> lookup(seq);
+  const ParserAtom* wk = wellKnownTable_.lookupChar16Seq(lookup);
+  if (wk) {
+    return AddPtr(wk);
+  }
+
+  // Check for existing atom.
+  return AddPtr(entrySet_.lookupForAdd(lookup), lookup.hash());
+}
+
 JS::Result<const ParserAtom*, OOM&> ParserAtomsTable::addEntry(
     JSContext* cx, AddPtr& addPtr, UniquePtr<ParserAtomEntry> entry) {
   ParserAtomEntry* entryPtr = entry.get();
   MOZ_ASSERT(!addPtr);
   if (!entrySet_.add(addPtr.inner().entrySetAddPtr, std::move(entry))) {
     return RaiseParserAtomsOOMError(cx);
   }
   return entryPtr->asAtom();
 }
 
-static const uint16_t MAX_LATIN1_CHAR = 0xff;
-
 template <typename AtomCharT, typename SeqCharT>
 JS::Result<const ParserAtom*, OOM&> ParserAtomsTable::internChar16Seq(
     JSContext* cx, AddPtr& addPtr, InflatedChar16Sequence<SeqCharT> seq,
     uint32_t length) {
   MOZ_ASSERT(!addPtr);
 
   UniquePtr<ParserAtomEntry> entry;
 
@@ -221,29 +233,17 @@ JS::Result<const ParserAtom*, OOM&> Pars
     return RaiseParserAtomsOOMError(cx);
   }
   ParserAtomEntry::drainChar16Seq<AtomCharT, SeqCharT>(copy.get(), seq, length);
   MOZ_TRY_VAR(entry, ParserAtomEntry::allocate(cx, std::move(copy), length,
                                                addPtr.inner().hash));
   return addEntry(cx, addPtr, std::move(entry));
 }
 
-template <typename CharT>
-ParserAtomsTable::AddPtr ParserAtomsTable::lookupForAdd(
-    JSContext* cx, InflatedChar16Sequence<CharT> seq) {
-  // Check against well-known.
-  SpecificParserAtomLookup<CharT> lookup(seq);
-  const ParserAtom* wk = wellKnownTable_.lookupChar16Seq(lookup);
-  if (wk) {
-    return AddPtr(wk);
-  }
-
-  // Check for existing atom.
-  return AddPtr(entrySet_.lookupForAdd(lookup), lookup.hash());
-}
+static const uint16_t MAX_LATIN1_CHAR = 0xff;
 
 template <typename CharT>
 JS::Result<const ParserAtom*, OOM&> ParserAtomsTable::lookupOrInternChar16Seq(
     JSContext* cx, InflatedChar16Sequence<CharT> seq) {
   // Check for well-known or existing.
   AddPtr addPtr = lookupForAdd(cx, seq);
   if (addPtr) {
     return addPtr.get()->asAtom();
@@ -259,23 +259,16 @@ JS::Result<const ParserAtom*, OOM&> Pars
     length += 1;
   }
 
   // Otherwise, add new entry.
   return wide ? internChar16Seq<char16_t>(cx, addPtr, seq, length)
               : internChar16Seq<Latin1Char>(cx, addPtr, seq, length);
 }
 
-JS::Result<const ParserAtom*, OOM&> ParserAtomsTable::internChar16(
-    JSContext* cx, const char16_t* char16Ptr, uint32_t length) {
-  InflatedChar16Sequence<char16_t> seq(char16Ptr, length);
-
-  return lookupOrInternChar16Seq(cx, seq);
-}
-
 JS::Result<const ParserAtom*, OOM&> ParserAtomsTable::internAscii(
     JSContext* cx, const char* asciiPtr, uint32_t length) {
   // ASCII strings are strict subsets of Latin1 strings.
   const Latin1Char* latin1Ptr = reinterpret_cast<const Latin1Char*>(asciiPtr);
   return internLatin1(cx, latin1Ptr, length);
 }
 
 JS::Result<const ParserAtom*, OOM&> ParserAtomsTable::internLatin1(
@@ -322,16 +315,23 @@ JS::Result<const ParserAtom*, OOM&> Pars
 
   InflatedChar16Sequence<mozilla::Utf8Unit> seq(utf8Ptr, nbyte);
 
   // Otherwise, slowpath lookup/interning path that identifies the
   // proper target encoding.
   return lookupOrInternChar16Seq(cx, seq);
 }
 
+JS::Result<const ParserAtom*, OOM&> ParserAtomsTable::internChar16(
+    JSContext* cx, const char16_t* char16Ptr, uint32_t length) {
+  InflatedChar16Sequence<char16_t> seq(char16Ptr, length);
+
+  return lookupOrInternChar16Seq(cx, seq);
+}
+
 JS::Result<const ParserAtom*, OOM&> ParserAtomsTable::internJSAtom(
     JSContext* cx, CompilationInfo& compilationInfo, JSAtom* atom) {
   const ParserAtom* id;
   {
     JS::AutoCheckCannotGC nogc;
 
     auto result =
         atom->hasLatin1Chars()
--- a/js/src/frontend/ParserAtom.h
+++ b/js/src/frontend/ParserAtom.h
@@ -443,49 +443,50 @@ class ParserAtomsTable {
       return atomOrAdd.is<const ParserAtomEntry*>();
     }
     const ParserAtomEntry* get() const {
       return atomOrAdd.as<const ParserAtomEntry*>();
     }
     InnerAddPtr& inner() { return atomOrAdd.as<InnerAddPtr>(); }
   };
 
+  // Look up a sequence pointer for add.  Returns either the found
+  // parser-atom pointer, or and AddPtr to insert into the entry-set.
+  template <typename CharT>
+  AddPtr lookupForAdd(JSContext* cx, InflatedChar16Sequence<CharT> seq);
+
+  // Internal APIs for interning to the table after well-known atoms cases have
+  // been tested.
   JS::Result<const ParserAtom*, OOM&> addEntry(
       JSContext* cx, AddPtr& addPtr, UniquePtr<ParserAtomEntry> entry);
-
   template <typename AtomCharT, typename SeqCharT>
   JS::Result<const ParserAtom*, OOM&> internChar16Seq(
       JSContext* cx, AddPtr& add, InflatedChar16Sequence<SeqCharT> seq,
       uint32_t length);
 
-  // Look up a sequence pointer for add.  Returns either the found
-  // parser-atom pointer, or and AddPtr to insert into the entry-set.
-  template <typename CharT>
-  AddPtr lookupForAdd(JSContext* cx, InflatedChar16Sequence<CharT> seq);
-
   template <typename CharT>
   JS::Result<const ParserAtom*, OOM&> lookupOrInternChar16Seq(
       JSContext* cx, InflatedChar16Sequence<CharT> seq);
 
  public:
-  JS::Result<const ParserAtom*, OOM&> internChar16(JSContext* cx,
-                                                   const char16_t* char16Ptr,
-                                                   uint32_t length);
-
   JS::Result<const ParserAtom*, OOM&> internAscii(JSContext* cx,
                                                   const char* asciiPtr,
                                                   uint32_t length);
 
   JS::Result<const ParserAtom*, OOM&> internLatin1(JSContext* cx,
                                                    const Latin1Char* latin1Ptr,
                                                    uint32_t length);
 
   JS::Result<const ParserAtom*, OOM&> internUtf8(
       JSContext* cx, const mozilla::Utf8Unit* utf8Ptr, uint32_t nbyte);
 
+  JS::Result<const ParserAtom*, OOM&> internChar16(JSContext* cx,
+                                                   const char16_t* char16Ptr,
+                                                   uint32_t length);
+
   JS::Result<const ParserAtom*, OOM&> internJSAtom(
       JSContext* cx, CompilationInfo& compilationInfo, JSAtom* atom);
 
   JS::Result<const ParserAtom*, OOM&> concatAtoms(
       JSContext* cx, mozilla::Range<const ParserAtom*> atoms);
 };
 
 template <typename CharT>