Bug 1467336 - Move skipChars to SourceUnits::skipCodeUnits, and make it efficient in the obvious way. r=arai
authorJeff Walden <jwalden@mit.edu>
Fri, 08 Jun 2018 11:48:38 -0700
changeset 476725 2b5d5815e7ef2cb3fbfb0f62c3175a418dd8ad52
parent 476724 673d93f7c030c02f2ed3d70d77a7a2ba9e017312
child 476726 18c217828e1b5d7ce2b945ac10ba935592f60f7d
push id9374
push userjlund@mozilla.com
push dateMon, 18 Jun 2018 21:43:20 +0000
treeherdermozilla-beta@160e085dfb0b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersarai
bugs1467336
milestone62.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 1467336 - Move skipChars to SourceUnits::skipCodeUnits, and make it efficient in the obvious way. r=arai
js/src/frontend/TokenStream.cpp
js/src/frontend/TokenStream.h
--- a/js/src/frontend/TokenStream.cpp
+++ b/js/src/frontend/TokenStream.cpp
@@ -1121,29 +1121,29 @@ TokenStreamSpecific<CharT, AnyCharsAcces
 }
 
 template<typename CharT, class AnyCharsAccess>
 uint32_t
 TokenStreamSpecific<CharT, AnyCharsAccess>::matchUnicodeEscapeIdStart(uint32_t* codePoint)
 {
     uint32_t length = peekUnicodeEscape(codePoint);
     if (length > 0 && unicode::IsIdentifierStart(*codePoint)) {
-        skipChars(length);
+        sourceUnits.skipCodeUnits(length);
         return length;
     }
     return 0;
 }
 
 template<typename CharT, class AnyCharsAccess>
 bool
 TokenStreamSpecific<CharT, AnyCharsAccess>::matchUnicodeEscapeIdent(uint32_t* codePoint)
 {
     uint32_t length = peekUnicodeEscape(codePoint);
     if (length > 0 && unicode::IsIdentifierPart(*codePoint)) {
-        skipChars(length);
+        sourceUnits.skipCodeUnits(length);
         return true;
     }
     return false;
 }
 
 // Helper function which returns true if the first length(q) characters in p are
 // the same as the characters in q.
 template<typename CharT>
@@ -1216,17 +1216,17 @@ TokenStreamSpecific<CharT, AnyCharsAcces
     if (!CharsMatch(peeked, directive))
         return true;
 
     if (shouldWarnDeprecated) {
         if (!warning(JSMSG_DEPRECATED_PRAGMA, errorMsgPragma))
             return false;
     }
 
-    skipChars(directiveLength);
+    sourceUnits.skipCodeUnits(directiveLength);
     tokenbuf.clear();
 
     do {
         int32_t c;
         if (!peekChar(&c))
             return false;
 
         if (c == EOF || unicode::IsSpaceOrBOM2(c))
@@ -2505,17 +2505,17 @@ TokenStreamSpecific<CharT, AnyCharsAcces
                 if (JS7_ISHEX(c2) &&
                     sourceUnits.peekCodeUnits(3, cp) &&
                     JS7_ISHEX(cp[0]) && JS7_ISHEX(cp[1]) && JS7_ISHEX(cp[2]))
                 {
                     unit = (JS7_UNHEX(c2) << 12) |
                            (JS7_UNHEX(cp[0]) << 8) |
                            (JS7_UNHEX(cp[1]) << 4) |
                            JS7_UNHEX(cp[2]);
-                    skipChars(3);
+                    sourceUnits.skipCodeUnits(3);
                 } else {
                     // Beware: |c2| may not be an ASCII code point here!
                     ungetCodeUnit(c2);
                     uint32_t start = sourceUnits.offset() - 2;
                     if (parsingTemplate) {
                         TokenStreamAnyChars& anyChars = anyCharsAccess();
                         anyChars.setInvalidTemplateEscape(start, InvalidEscapeType::Unicode);
                         continue;
@@ -2528,17 +2528,17 @@ TokenStreamSpecific<CharT, AnyCharsAcces
 
               // Hexadecimal character specification.
               case 'x': {
                 CharT cp[2];
                 if (sourceUnits.peekCodeUnits(2, cp) &&
                     JS7_ISHEX(cp[0]) && JS7_ISHEX(cp[1]))
                 {
                     unit = (JS7_UNHEX(cp[0]) << 4) + JS7_UNHEX(cp[1]);
-                    skipChars(2);
+                    sourceUnits.skipCodeUnits(2);
                 } else {
                     uint32_t start = sourceUnits.offset() - 2;
                     if (parsingTemplate) {
                         TokenStreamAnyChars& anyChars = anyCharsAccess();
                         anyChars.setInvalidTemplateEscape(start, InvalidEscapeType::Hexadecimal);
                         continue;
                     }
                     reportInvalidEscapeError(start, InvalidEscapeType::Hexadecimal);
--- a/js/src/frontend/TokenStream.h
+++ b/js/src/frontend/TokenStream.h
@@ -955,16 +955,23 @@ class SourceUnits
         MOZ_ASSERT(ptr, "shouldn't peek into poisoned SourceUnits");
         if (n > mozilla::PointerRangeSize(ptr, limit_))
             return false;
 
         std::copy_n(ptr, n, out);
         return true;
     }
 
+    void skipCodeUnits(uint32_t n) {
+        MOZ_ASSERT(ptr, "shouldn't use poisoned SourceUnits");
+        MOZ_ASSERT(n <= mozilla::PointerRangeSize(ptr, limit_),
+                   "shouldn't skip beyond end of SourceUnits");
+        ptr += n;
+    }
+
     bool matchCodeUnit(CharT c) {
         if (*ptr == c) {    // this will nullptr-crash if poisoned
             ptr++;
             return true;
         }
         return false;
     }
 
@@ -1856,24 +1863,16 @@ class MOZ_STACK_CLASS TokenStreamSpecifi
     }
 
     MOZ_MUST_USE bool peekChar(int32_t* c) {
         if (!getChar(c))
             return false;
         ungetChar(*c);
         return true;
     }
-
-    void skipChars(uint32_t n) {
-        while (n-- > 0) {
-            MOZ_ASSERT(!sourceUnits.atEnd());
-            mozilla::DebugOnly<int32_t> c = getCodeUnit();
-            MOZ_ASSERT(!SourceUnits::isRawEOLChar(c));
-        }
-    }
 };
 
 // It's preferable to define this in TokenStream.cpp, but its template-ness
 // means we'd then have to *instantiate* this constructor for all possible
 // (CharT, AnyCharsAccess) pairs -- and that gets super-messy as AnyCharsAccess
 // *itself* is templated.  This symbol really isn't that huge compared to some
 // defined inline in TokenStreamSpecific, so just rely on the linker commoning
 // stuff up.