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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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                    }
Note: See TracChangeset for help on using the changeset viewer.