From e5921d70f1555e262e283660df0cfd87698e6c96 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Wed, 16 Mar 2011 15:17:21 -0700 Subject: [PATCH] Bug 639420 - Speed up the scanner ten ways, part 4. r=brendan. --- js/src/jsscan.cpp | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/js/src/jsscan.cpp b/js/src/jsscan.cpp index 65dde60c326..5a88a4cd3e8 100644 --- a/js/src/jsscan.cpp +++ b/js/src/jsscan.cpp @@ -296,7 +296,10 @@ TokenStream::getChar() /* * This gets the next char. It does nothing special with EOL sequences, not - * even updating the line counters. + * even updating the line counters. It can be used safely if (a) the + * resulting char is guaranteed to be ungotten (by ungetCharIgnoreEOL()) if + * it's an EOL, and (b) the line-related state (lineno, linebase) is not used + * before it's ungotten. */ int32 TokenStream::getCharIgnoreEOL() @@ -339,7 +342,6 @@ TokenStream::ungetCharIgnoreEOL(int32 c) { if (c == EOF) return; - JS_ASSERT(TokenBuf::isRawEOLChar(c)); JS_ASSERT(!userbuf.atStart()); userbuf.ungetRawChar(); } @@ -1111,30 +1113,30 @@ TokenStream::getTokenInternal() decimal: bool hasFracOrExp = false; while (JS7_ISDEC(c)) - c = getChar(); + c = getCharIgnoreEOL(); if (c == '.') { hasFracOrExp = true; do { - c = getChar(); + c = getCharIgnoreEOL(); } while (JS7_ISDEC(c)); } if (JS_TOLOWER(c) == 'e') { hasFracOrExp = true; - c = getChar(); + c = getCharIgnoreEOL(); if (c == '+' || c == '-') - c = getChar(); + c = getCharIgnoreEOL(); if (!JS7_ISDEC(c)) { - ungetChar(c); + ungetCharIgnoreEOL(c); ReportCompileErrorNumber(cx, this, NULL, JSREPORT_ERROR, JSMSG_MISSING_EXPONENT); goto error; } do { - c = getChar(); + c = getCharIgnoreEOL(); } while (JS7_ISDEC(c)); } - ungetChar(c); + ungetCharIgnoreEOL(c); if (JS_ISIDSTART(c)) { ReportCompileErrorNumber(cx, this, NULL, JSREPORT_ERROR, JSMSG_IDSTART_AFTER_NUMBER); @@ -1166,18 +1168,18 @@ TokenStream::getTokenInternal() if (c == '0') { int radix; - c = getChar(); + c = getCharIgnoreEOL(); if (JS_TOLOWER(c) == 'x') { radix = 16; - c = getChar(); + c = getCharIgnoreEOL(); if (!JS7_ISHEX(c)) { - ungetChar(c); + ungetCharIgnoreEOL(c); ReportCompileErrorNumber(cx, this, NULL, JSREPORT_ERROR, JSMSG_MISSING_HEXDIGITS); goto error; } numStart = userbuf.addressOfNextRawChar() - 1; while (JS7_ISHEX(c)) - c = getChar(); + c = getCharIgnoreEOL(); } else if (JS7_ISDEC(c)) { radix = 8; numStart = userbuf.addressOfNextRawChar() - 1; @@ -1199,7 +1201,7 @@ TokenStream::getTokenInternal() } goto decimal; /* use the decimal scanner for the rest of the number */ } - c = getChar(); + c = getCharIgnoreEOL(); } } else { /* '0' not followed by 'x', 'X' or a digit; scan as a decimal number. */ @@ -1207,7 +1209,7 @@ TokenStream::getTokenInternal() numStart = userbuf.addressOfNextRawChar() - 1; goto decimal; } - ungetChar(c); + ungetCharIgnoreEOL(c); if (JS_ISIDSTART(c)) { ReportCompileErrorNumber(cx, this, NULL, JSREPORT_ERROR, JSMSG_IDSTART_AFTER_NUMBER);