Bug 564369 - streamline TokenStream::getChar(), part 9. r=cdleary.
authorNicholas Nethercote <nnethercote@mozilla.com>
Wed, 12 May 2010 21:43:01 -0700
changeset 42703 01f9e6ca37e1e7a81273dc97583debdefcf64326
parent 42702 ad37e6e5bb42bd7d6f3ada46c9369c056db0b1bc
child 42704 ffbe83895f69b3022ca2b4d13db5686d32d06e76
push id1
push userroot
push dateTue, 26 Apr 2011 22:38:44 +0000
treeherdermozilla-beta@bfdb6e623a36 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerscdleary
bugs564369
milestone1.9.3a5pre
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
Bug 564369 - streamline TokenStream::getChar(), part 9. r=cdleary.
js/src/jsscan.cpp
js/src/jsscan.h
--- a/js/src/jsscan.cpp
+++ b/js/src/jsscan.cpp
@@ -172,17 +172,17 @@ js_IsIdentifier(JSString *str)
 #ifdef _MSC_VER
 #pragma warning(push)
 #pragma warning(disable:4351)
 #endif
 
 /* Initialize members that aren't initialized in |init|. */
 TokenStream::TokenStream(JSContext *cx)
   : cx(cx), tokens(), cursor(), lookahead(), ungetpos(), ungetbuf(), flags(),
-    linelen(), linepos(), file(), listenerTSData(), tokenbuf(cx)
+    linepos(), lineposNext(), file(), listenerTSData(), tokenbuf(cx)
 {}
 
 #ifdef _MSC_VER
 #pragma warning(pop)
 #endif
 
 bool
 TokenStream::init(const jschar *base, size_t length, FILE *fp, const char *fn, uintN ln)
@@ -390,27 +390,21 @@ TokenStream::getChar()
             ulen = i;
             userbuf.ptr += ulen;
 
             /* Reset linebuf based on normalized length. */
             linebuf.ptr = linebuf.base;
             linebuf.limit = linebuf.base + ulen + llenAdjust;
 
             /* Update position of linebuf within physical userbuf line. */
-            if (!(flags & TSF_NLFLAG))
-                linepos += linelen;
-            else
-                linepos = 0;
+            linepos = lineposNext;
             if (linebuf.limit[-1] == '\n')
-                flags |= TSF_NLFLAG;
+                lineposNext = 0;
             else
-                flags &= ~TSF_NLFLAG;
-
-            /* Update linelen from un-normalized length. */
-            linelen = ulen;
+                lineposNext += ulen;
         }
         c = *linebuf.ptr++;
     }
     if (c == '\n')
         lineno++;
     return c;
 }
 
--- a/js/src/jsscan.h
+++ b/js/src/jsscan.h
@@ -250,27 +250,25 @@ struct Token {
 };
 
 enum TokenStreamFlags
 {
     TSF_ERROR = 0x01,           /* fatal error while compiling */
     TSF_EOF = 0x02,             /* hit end of file */
     TSF_NEWLINES = 0x04,        /* tokenize newlines */
     TSF_OPERAND = 0x08,         /* looking for operand, not operator */
-    TSF_NLFLAG = 0x20,          /* last linebuf ended with \n */
+    TSF_UNEXPECTED_EOF = 0x10,  /* unexpected end of input, i.e. TOK_EOF not at top-level. */
+    TSF_KEYWORD_IS_NAME = 0x20, /* Ignore keywords and return TOK_NAME instead to the parser. */
     TSF_STRICT_MODE_CODE = 0x40,/* Tokenize as appropriate for strict mode code. */
     TSF_DIRTYLINE = 0x80,       /* non-whitespace since start of line */
     TSF_OWNFILENAME = 0x100,    /* ts->filename is malloc'd */
     TSF_XMLTAGMODE = 0x200,     /* scanning within an XML tag in E4X */
     TSF_XMLTEXTMODE = 0x400,    /* scanning XMLText terminal from E4X */
     TSF_XMLONLYMODE = 0x800,    /* don't scan {expr} within text/tag */
 
-    /* Flag indicating unexpected end of input, i.e. TOK_EOF not at top-level. */
-    TSF_UNEXPECTED_EOF = 0x1000,
-
     /*
      * To handle the hard case of contiguous HTML comments, we want to clear the
      * TSF_DIRTYINPUT flag at the end of each such comment.  But we'd rather not
      * scan for --> within every //-style comment unless we have to.  So we set
      * TSF_IN_HTML_COMMENT when a <!-- is scanned as an HTML begin-comment, and
      * clear it (and TSF_DIRTYINPUT) when we scan --> either on a clean line, or
      * only if (ts->flags & TSF_IN_HTML_COMMENT), in a //-style comment.
      *
@@ -280,20 +278,17 @@ enum TokenStreamFlags
      *      <!-- comment hiding hack #1
      *      code goes here
      *      // --> oops, markup for script-unaware browsers goes here!
      *    </script>
      *
      * It does not cope with malformed comment hiding hacks where --> is hidden
      * by C-style comments, or on a dirty line.  Such cases are already broken.
      */
-    TSF_IN_HTML_COMMENT = 0x2000,
-
-    /* Ignore keywords and return TOK_NAME instead to the parser. */
-    TSF_KEYWORD_IS_NAME = 0x4000
+    TSF_IN_HTML_COMMENT = 0x2000
 };
 
 #define t_op            u.s.op
 #define t_reflags       u.reflags
 #define t_atom          u.s.atom
 #define t_atom2         u.p.atom2
 #define t_dval          u.dval
 
@@ -482,18 +477,18 @@ class TokenStream
     JSContext           * const cx;
     Token               tokens[ntokens];/* circular token buffer */
     uintN               cursor;         /* index of last parsed token */
     uintN               lookahead;      /* count of lookahead tokens */
     uintN               lineno;         /* current line number */
     uintN               ungetpos;       /* next free char slot in ungetbuf */
     jschar              ungetbuf[6];    /* at most 6, for \uXXXX lookahead */
     uintN               flags;          /* flags -- see above */
-    uint32              linelen;        /* physical linebuf segment length */
     uint32              linepos;        /* linebuf offset in physical line */
+    uint32              lineposNext;    /* the next value of linepos */
     TokenBuf            linebuf;        /* line buffer for diagnostics */
     TokenBuf            userbuf;        /* user input buffer if !file */
     const char          *filename;      /* input filename or null */
     FILE                *file;          /* stdio stream if reading from file */
     JSSourceHandler     listener;       /* callback for source; eg debugger */
     void                *listenerData;  /* listener 'this' data */
     void                *listenerTSData;/* listener data for this TokenStream */
     JSCharBuffer        tokenbuf;       /* current token string buffer */