Ignore:
Timestamp:
May 2, 2009, 4:33:56 AM (16 years ago)
Author:
[email protected]
Message:

2009-05-02 Maciej Stachowiak <[email protected]>

Reviewed by Cameron Zwarich.

  • speed up the lexer in various ways

~2% command-line SunSpider speedup

  • parser/Lexer.cpp: (JSC::Lexer::setCode): Moved below shift() so it can inline. (JSC::Lexer::scanRegExp): Use resize(0) instead of clear() on Vectors, since the intent here is not to free the underlying buffer. (JSC::Lexer::lex): ditto; also, change the loop logic a bit for the main lexing loop to avoid branching on !m_done twice per iteration. Now we only check it once. (JSC::Lexer::shift): Make this ALWAYS_INLINE and tag an unusual branch as UNLIKELY
  • parser/Lexer.h: (JSC::Lexer::makeIdentifier): force to be ALWAYS_INLINE
  • wtf/Vector.h: (WTF::::append): force to be ALWAYS_INLINE (may have helped in ways other than parsing but it wasn't getting inlined in a hot code path in the lexer)
File:
1 edited

Legend:

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

    r41045 r43144  
    8989}
    9090
    91 void Lexer::setCode(const SourceCode& source)
    92 {
    93     yylineno = source.firstLine();
    94     m_restrKeyword = false;
    95     m_delimited = false;
    96     m_eatNextIdentifier = false;
    97     m_stackToken = -1;
    98     m_lastToken = -1;
    99 
    100     m_position = source.startOffset();
    101     m_source = &source;
    102     m_code = source.provider()->data();
    103     m_length = source.endOffset();
    104     m_skipLF = false;
    105     m_skipCR = false;
    106     m_error = false;
    107     m_atLineStart = true;
    108 
    109     // read first characters
    110     shift(4);
    111 }
    112 
    113 void Lexer::shift(unsigned p)
     91ALWAYS_INLINE void Lexer::shift(unsigned p)
    11492{
    11593    // ECMA-262 calls for stripping Cf characters here, but we only do this for BOM,
     
    132110            m_nextOffset3 = m_position;
    133111            m_next3 = m_code[m_position++];
    134         } while (m_next3 == 0xFEFF);
    135     }
     112        } while (UNLIKELY(m_next3 == 0xFEFF));
     113    }
     114}
     115
     116void Lexer::setCode(const SourceCode& source)
     117{
     118    yylineno = source.firstLine();
     119    m_restrKeyword = false;
     120    m_delimited = false;
     121    m_eatNextIdentifier = false;
     122    m_stackToken = -1;
     123    m_lastToken = -1;
     124
     125    m_position = source.startOffset();
     126    m_source = &source;
     127    m_code = source.provider()->data();
     128    m_length = source.endOffset();
     129    m_skipLF = false;
     130    m_skipCR = false;
     131    m_error = false;
     132    m_atLineStart = true;
     133
     134    // read first characters
     135    shift(4);
    136136}
    137137
     
    156156    m_state = Start;
    157157    unsigned short stringType = 0; // either single or double quotes
    158     m_buffer8.clear();
    159     m_buffer16.clear();
     158    m_buffer8.resize(0);
     159    m_buffer16.resize(0);
    160160    m_done = false;
    161161    m_terminator = false;
     
    171171    }
    172172    int startOffset = m_currentOffset;
    173     while (!m_done) {
     173    if (!m_done) {
     174    while (true) {
    174175        if (m_skipLF && m_current != '\n') // found \r but not \n afterwards
    175176            m_skipLF = false;
     
    452453        }
    453454
    454         // move on to the next character
    455         if (!m_done)
    456             shift(1);
    457455        if (m_state != Start && m_state != InSingleLineComment)
    458456            m_atLineStart = false;
     457        if (m_done)
     458            break;
     459
     460        shift(1);
     461    }
    459462    }
    460463
     
    843846bool Lexer::scanRegExp()
    844847{
    845     m_buffer16.clear();
     848    m_buffer16.resize(0);
    846849    bool lastWasEscape = false;
    847850    bool inBrackets = false;
     
    863866        } else { // end of regexp
    864867            m_pattern = UString(m_buffer16);
    865             m_buffer16.clear();
     868            m_buffer16.resize(0);
    866869            shift(1);
    867870            break;
Note: See TracChangeset for help on using the changeset viewer.