Changeset 59061 in webkit for trunk/JavaScriptCore/parser


Ignore:
Timestamp:
May 9, 2010, 2:16:16 PM (15 years ago)
Author:
[email protected]
Message:

Reserve a large-ish initial capacity for Lexer::m_buffer16.

Reviewed by Oliver Hunt.

SunSpider says 0.3% faster.

m_buffer16 is used when parsing complex strings -- for example, strings
with escape sequences in them. These kinds of strings can be really long,
and we want to avoid repeatedly copying as we grow m_buffer16.

The net memory cost is quite low, since it's proporitional to source
code we already have in memory, and we throw away m_buffer16 right when
we're done parsing.

  • parser/Lexer.cpp:

(JSC::Lexer::Lexer): No need to reserve initial capacity in our constructor,
since setCode will be called before we're asked to lex anything.
(JSC::Lexer::setCode): Reserve enough space to lex half the source code
as a complex string without having to copy.
(JSC::Lexer::clear): No need to reserve initial capacity here either,
since setCode will be called before we're asked to lex anything.

File:
1 edited

Legend:

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

    r53224 r59061  
    5353    , m_keywordTable(JSC::mainTable)
    5454{
    55     m_buffer8.reserveInitialCapacity(initialReadBufferCapacity);
    56     m_buffer16.reserveInitialCapacity(initialReadBufferCapacity);
    5755}
    5856
     
    149147    m_error = false;
    150148    m_atLineStart = true;
     149
     150    m_buffer8.reserveInitialCapacity(initialReadBufferCapacity);
     151    m_buffer16.reserveInitialCapacity((m_codeEnd - m_code) / 2);
    151152
    152153    // ECMA-262 calls for stripping all Cf characters, but we only strip BOM characters.
     
    10101011
    10111012    Vector<char> newBuffer8;
    1012     newBuffer8.reserveInitialCapacity(initialReadBufferCapacity);
    10131013    m_buffer8.swap(newBuffer8);
    10141014
    10151015    Vector<UChar> newBuffer16;
    1016     newBuffer16.reserveInitialCapacity(initialReadBufferCapacity);
    10171016    m_buffer16.swap(newBuffer16);
    10181017
Note: See TracChangeset for help on using the changeset viewer.