Changeset 62031 in webkit for trunk/JavaScriptCore/parser/Lexer.h


Ignore:
Timestamp:
Jun 28, 2010, 1:17:13 PM (15 years ago)
Author:
[email protected]
Message:

Only one character lookahead should be enough for the lexer
https://bugs.webkit.org/show_bug.cgi?id=41213

Reviewed by Oliver Hunt.

The lexer had 4 character lookahead before, which required
a complex shifting mechanism. This can be improved by using
only one character lookahead for most decisions, and a
peek() function as a fallback when it is absolutely necessary.

  • parser/Lexer.cpp:

(JSC::Lexer::currentCharacter):
(JSC::Lexer::currentOffset):
(JSC::Lexer::setCode):
(JSC::Lexer::shift):
(JSC::Lexer::peek):
(JSC::Lexer::getUnicodeCharacter):
(JSC::Lexer::shiftLineTerminator):
(JSC::Lexer::lastTokenWasRestrKeyword):
(JSC::Lexer::lex):
(JSC::Lexer::scanRegExp):
(JSC::Lexer::skipRegExp):

  • parser/Lexer.h:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/parser/Lexer.h

    r61732 r62031  
    22 *  Copyright (C) 1999-2000 Harri Porten ([email protected])
    33 *  Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserved.
     4 *  Copyright (C) 2010 Zoltan Herczeg ([email protected])
    45 *
    56 *  This library is free software; you can redistribute it and/or
     
    2728#include "SourceCode.h"
    2829#include <wtf/ASCIICType.h>
     30#include <wtf/AlwaysInline.h>
    2931#include <wtf/SegmentedVector.h>
    3032#include <wtf/Vector.h>
     
    6769        ~Lexer();
    6870
    69         void shift1();
    70         void shift2();
    71         void shift3();
    72         void shift4();
    73         void shiftLineTerminator();
    74 
    7571        void record8(int);
    7672        void record16(int);
     
    7975        void copyCodeWithoutBOMs();
    8076
    81         int currentOffset() const;
    82         const UChar* currentCharacter() const;
     77        ALWAYS_INLINE void shift();
     78        ALWAYS_INLINE int peek(int offset);
     79        int getUnicodeCharacter();
     80        void shiftLineTerminator();
    8381
    84         const Identifier* makeIdentifier(const UChar* characters, size_t length);
     82        ALWAYS_INLINE const UChar* currentCharacter() const;
     83        ALWAYS_INLINE int currentOffset() const;
    8584
    86         bool lastTokenWasRestrKeyword() const;
     85        ALWAYS_INLINE const Identifier* makeIdentifier(const UChar* characters, size_t length);
     86
     87        ALWAYS_INLINE bool lastTokenWasRestrKeyword() const;
    8788
    8889        static const size_t initialReadBufferCapacity = 32;
     
    107108        // current and following unicode characters (int to allow for -1 for end-of-file marker)
    108109        int m_current;
    109         int m_next1;
    110         int m_next2;
    111         int m_next3;
    112        
     110
    113111        IdentifierArena* m_arena;
    114112
Note: See TracChangeset for help on using the changeset viewer.