Changeset 38632 in webkit for trunk/JavaScriptCore/parser


Ignore:
Timestamp:
Nov 20, 2008, 2:27:34 PM (17 years ago)
Author:
[email protected]
Message:

2008-11-20 Sam Weinig <[email protected]>

Reviewed by Geoffrey Garen.

Speedup the lexer to offset coming re-parsing patch.

  • .6% progression on Sunspider.
  • bytecompiler/SegmentedVector.h: (JSC::SegmentedVector::shrink): Fixed bug where m_size would not be set when shrinking to 0.
  • parser/Lexer.cpp: (JSC::Lexer::Lexer): (JSC::Lexer::isIdentStart): Use isASCIIAlpha and isASCII to avoid going into ICU in the common cases. (JSC::Lexer::isIdentPart): Use isASCIIAlphanumeric and isASCII to avoid going into ICU in the common cases (JSC::isDecimalDigit): Use version in ASCIICType.h. Inlining it was a regression. (JSC::Lexer::isHexDigit): Ditto. (JSC::Lexer::isOctalDigit): Ditto. (JSC::Lexer::clear): Resize the m_identifiers SegmentedVector to initial capacity
  • parser/Lexer.h: Remove unused m_strings vector. Make m_identifiers a SegmentedVector<Identifier> to avoid allocating a new Identifier* for each identifier found. The SegmentedVector is need so we can passes references to the Identifier to the parser, which remain valid even when the vector is resized. (JSC::Lexer::makeIdentifier): Inline and return a reference to the added Identifier.
Location:
trunk/JavaScriptCore/parser
Files:
2 edited

Legend:

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

    r38390 r38632  
    5858static bool isDecimalDigit(int);
    5959
    60 static const size_t initialReadBufferCapacity = 32;
    61 static const size_t initialStringTableCapacity = 64;
    62 
    6360Lexer::Lexer(JSGlobalData* globalData)
    6461    : yylineno(1)
     
    8481    m_buffer8.reserveCapacity(initialReadBufferCapacity);
    8582    m_buffer16.reserveCapacity(initialReadBufferCapacity);
    86     m_strings.reserveCapacity(initialStringTableCapacity);
    87     m_identifiers.reserveCapacity(initialStringTableCapacity);
    8883}
    8984
     
    609604bool Lexer::isIdentStart(int c)
    610605{
    611     return (category(c) & (Letter_Uppercase | Letter_Lowercase | Letter_Titlecase | Letter_Modifier | Letter_Other))
    612         || c == '$' || c == '_';
     606    return isASCIIAlpha(c) || c == '$' || c == '_' || (!isASCII(c) && (category(c) & (Letter_Uppercase | Letter_Lowercase | Letter_Titlecase | Letter_Modifier | Letter_Other)));
    613607}
    614608
    615609bool Lexer::isIdentPart(int c)
    616610{
    617     return (category(c) & (Letter_Uppercase | Letter_Lowercase | Letter_Titlecase | Letter_Modifier | Letter_Other
    618                             | Mark_NonSpacing | Mark_SpacingCombining | Number_DecimalDigit | Punctuation_Connector))
    619         || c == '$' || c == '_';
     611    return isASCIIAlphanumeric(c) || c == '$' || c == '_' || (!isASCII(c) && (category(c) & (Letter_Uppercase | Letter_Lowercase | Letter_Titlecase | Letter_Modifier | Letter_Other
     612                            | Mark_NonSpacing | Mark_SpacingCombining | Number_DecimalDigit | Punctuation_Connector)));
    620613}
    621614
    622615static bool isDecimalDigit(int c)
    623616{
    624     return (c >= '0' && c <= '9');
     617    return isASCIIDigit(c);
    625618}
    626619
    627620bool Lexer::isHexDigit(int c)
    628621{
    629     return (c >= '0' && c <= '9'
    630         || c >= 'a' && c <= 'f'
    631         || c >= 'A' && c <= 'F');
     622    return isASCIIHexDigit(c);
    632623}
    633624
    634625bool Lexer::isOctalDigit(int c)
    635626{
    636     return (c >= '0' && c <= '7');
     627    return isASCIIOctalDigit(c);
    637628}
    638629
     
    889880void Lexer::clear()
    890881{
    891     deleteAllValues(m_strings);
    892     Vector<UString*> newStrings;
    893     newStrings.reserveCapacity(initialStringTableCapacity);
    894     m_strings.swap(newStrings);
    895 
    896     deleteAllValues(m_identifiers);
    897     Vector<JSC::Identifier*> newIdentifiers;
    898     newIdentifiers.reserveCapacity(initialStringTableCapacity);
    899     m_identifiers.swap(newIdentifiers);
     882    m_identifiers.resize(0);
    900883
    901884    Vector<char> newBuffer8;
     
    911894}
    912895
    913 Identifier* Lexer::makeIdentifier(const Vector<UChar>& buffer)
    914 {
    915     JSC::Identifier* identifier = new JSC::Identifier(m_globalData, buffer.data(), buffer.size());
    916     m_identifiers.append(identifier);
    917     return identifier;
    918 }
    919 
    920896} // namespace JSC
  • trunk/JavaScriptCore/parser/Lexer.h

    r38205 r38632  
    2424#define Lexer_h
    2525
     26#include "Identifier.h"
    2627#include "Lookup.h"
    27 #include "UString.h"
     28#include "SegmentedVector.h"
     29#include "SourceCode.h"
    2830#include <wtf/Vector.h>
    29 #include "SourceCode.h"
    3031
    3132namespace JSC {
    3233
    33     class Identifier;
    3434    class RegExp;
    3535
     
    113113        void record16(UChar);
    114114
    115         JSC::Identifier* makeIdentifier(const Vector<UChar>& buffer);
     115        JSC::Identifier* makeIdentifier(const Vector<UChar>& buffer)
     116        {
     117            m_identifiers.append(JSC::Identifier(m_globalData, buffer.data(), buffer.size()));
     118            return &m_identifiers.last();
     119        }
     120
     121        static const size_t initialReadBufferCapacity = 32;
     122        static const size_t initialIdentifierTableCapacity = 64;
    116123
    117124        int yylineno;
     
    149156        int m_nextOffset3;
    150157       
    151         Vector<UString*> m_strings;
    152         Vector<JSC::Identifier*> m_identifiers;
     158        SegmentedVector<JSC::Identifier, initialIdentifierTableCapacity> m_identifiers;
    153159
    154160        JSGlobalData* m_globalData;
Note: See TracChangeset for help on using the changeset viewer.