Ignore:
Timestamp:
Jun 13, 2011, 3:38:22 PM (14 years ago)
Author:
[email protected]
Message:

2011-06-13 Oliver Hunt <[email protected]>

Reviewed by Gavin Barraclough.

Make it possible to inline the common case of identifier lexing
https://bugs.webkit.org/show_bug.cgi?id=62600

Add a lexing function that expects to lex an "normal" alpha numeric
identifier (that ignores keywords) so it's possible to inline the
common parsing cases. This comes out as a reasonable parsing speed
boost.

  • parser/JSParser.cpp: (JSC::JSParser::nextExpectIdentifier): (JSC::JSParser::parseProperty): (JSC::JSParser::parseMemberExpression):
  • parser/Lexer.cpp:
  • parser/Lexer.h: (JSC::Lexer::makeIdentifier): (JSC::Lexer::lexExpectIdentifier):
File:
1 edited

Legend:

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

    r88094 r88719  
    8989
    9090        SourceProvider* sourceProvider() const { return m_source->provider(); }
    91 
     91       
     92        JSTokenType lexExpectIdentifier(JSTokenData* lvalp, JSTokenInfo* llocp, unsigned, bool strictMode);
     93       
    9294    private:
    9395        friend class JSGlobalData;
     
    174176        return (convertHex(c1, c2) << 8) | convertHex(c3, c4);
    175177    }
     178   
     179    ALWAYS_INLINE const Identifier* Lexer::makeIdentifier(const UChar* characters, size_t length)
     180    {
     181        return &m_arena->makeIdentifier(m_globalData, characters, length);
     182    }
     183
     184    ALWAYS_INLINE JSTokenType Lexer::lexExpectIdentifier(JSTokenData* lvalp, JSTokenInfo* llocp, unsigned lexType, bool strictMode)
     185    {
     186        ASSERT((lexType & IgnoreReservedWords));
     187        const UChar* start = m_code;
     188        const UChar* ptr = start;
     189        const UChar* end = m_codeEnd;
     190        if (ptr >= end) {
     191            ASSERT(ptr == end);
     192            goto slowCase;
     193        }
     194        if (!WTF::isASCIIAlpha(*ptr))
     195            goto slowCase;
     196        ++ptr;
     197        while (ptr < end) {
     198            if (!WTF::isASCIIAlphanumeric(*ptr))
     199                break;
     200            ++ptr;
     201        }
     202
     203        // Here's the shift
     204        if (ptr < end) {
     205            if (!WTF::isASCII(*ptr) || (*ptr == '\\') || (*ptr == '_'))
     206                goto slowCase;
     207            m_current = *ptr;
     208        } else
     209            m_current = -1;
     210
     211        m_code = ptr;
     212
     213        // Create the identifier if needed
     214        if (lexType & DontBuildKeywords)
     215            lvalp->ident = 0;
     216        else
     217            lvalp->ident = makeIdentifier(start, ptr - start);
     218        llocp->line = m_lineNumber;
     219        llocp->startOffset = start - m_codeStart;
     220        llocp->endOffset = currentOffset();
     221        m_lastToken = IDENT;
     222        return IDENT;
     223       
     224    slowCase:
     225        return lex(lvalp, llocp, lexType, strictMode);
     226    }
    176227
    177228} // namespace JSC
Note: See TracChangeset for help on using the changeset viewer.