Changeset 44984 in webkit for trunk/JavaScriptCore


Ignore:
Timestamp:
Jun 23, 2009, 2:14:40 AM (16 years ago)
Author:
[email protected]
Message:

Fix stupid performance problem in the LiteralParser

Reviewed by Alexey Proskuryakov.

The LiteralParser was making a new UString in order to use
toDouble, however UString's toDouble allows a much wider range
of numberic strings than the LiteralParser accepts, and requires
an additional heap allocation or two for the construciton of the
UString. To rectify this we just call WTF::dtoa directly using
a stack allocated buffer to hold the validated numeric literal.

Location:
trunk/JavaScriptCore
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/ChangeLog

    r44974 r44984  
     12009-06-23  Oliver Hunt  <[email protected]>
     2
     3        Reviewed by Alexey Proskuryakov.
     4
     5        Fix stupid performance problem in the LiteralParser
     6
     7        The LiteralParser was making a new UString in order to use
     8        toDouble, however UString's toDouble allows a much wider range
     9        of numberic strings than the LiteralParser accepts, and requires
     10        an additional heap allocation or two for the construciton of the
     11        UString.  To rectify this we just call WTF::dtoa directly using
     12        a stack allocated buffer to hold the validated numeric literal.
     13
     14        * runtime/LiteralParser.cpp:
     15        (JSC::LiteralParser::Lexer::lexNumber):
     16        (JSC::LiteralParser::parse):
     17        * runtime/LiteralParser.h:
     18
    1192009-06-22  Oliver Hunt  <[email protected]>
    220
  • trunk/JavaScriptCore/runtime/LiteralParser.cpp

    r44924 r44984  
    3131#include "Lexer.h"
    3232#include <wtf/ASCIICType.h>
     33#include <wtf/dtoa.h>
    3334
    3435namespace JSC {
     
    264265    token.type = TokNumber;
    265266    token.end = m_ptr;
     267    Vector<char, 64> buffer(token.end - token.start + 1);
     268    int i;
     269    for (i = 0; i < token.end - token.start; i++) {
     270        ASSERT(static_cast<char>(token.start[i]) == token.start[i]);
     271        buffer[i] = static_cast<char>(token.start[i]);
     272    }
     273    buffer[i] = 0;
     274    char* end;
     275    token.numberToken = WTF::strtod(buffer.data(), &end);
     276    ASSERT(buffer.data() + (token.end - token.start) == end);
    266277    return TokNumber;
    267278}
     
    377388                        Lexer::LiteralParserToken numberToken = m_lexer.currentToken();
    378389                        m_lexer.next();
    379                         lastValue = jsNumber(m_exec, UString(numberToken.start, numberToken.end - numberToken.start).toDouble());
     390                        lastValue = jsNumber(m_exec, numberToken.numberToken);
    380391                        break;
    381392                    }
  • trunk/JavaScriptCore/runtime/LiteralParser.h

    r44923 r44984  
    6868                const UChar* end;
    6969                UString stringToken;
     70                double numberToken;
    7071            };
    7172            Lexer(const UString& s, ParserMode mode)
Note: See TracChangeset for help on using the changeset viewer.