Changeset 37048 in webkit


Ignore:
Timestamp:
Sep 28, 2008, 7:00:42 PM (17 years ago)
Author:
mrowe@apple.com
Message:

Speed up parseInt and parseFloat.

Repeatedly indexing into a UString is slow, so retrieve a pointer into the underlying buffer once up front
and use that instead. This is a 7% win on a parseInt/parseFloat micro-benchmark.

Reviewed by Cameron Zwarich.

Location:
trunk/JavaScriptCore
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/ChangeLog

    r37040 r37048  
     12008-09-28  Mark Rowe  <mrowe@apple.com>
     2
     3        Reviewed by Cameron Zwarich.
     4
     5        Speed up parseInt and parseFloat.
     6
     7        Repeatedly indexing into a UString is slow, so retrieve a pointer into the underlying buffer once up front
     8        and use that instead.  This is a 7% win on a parseInt/parseFloat micro-benchmark.
     9
     10        * kjs/JSGlobalObjectFunctions.cpp:
     11        (JSC::parseInt):
     12        (JSC::parseFloat):
     13
    1142008-09-28  Simon Hausmann  <hausmann@webkit.org>
    215
  • trunk/JavaScriptCore/kjs/JSGlobalObjectFunctions.cpp

    r36434 r37048  
    196196{
    197197    int length = s.size();
     198    const UChar* data = s.data();
    198199    int p = 0;
    199200
    200     while (p < length && isStrWhiteSpace(s[p]))
     201    while (p < length && isStrWhiteSpace(data[p]))
    201202        ++p;
    202203
    203204    double sign = 1;
    204205    if (p < length) {
    205         if (s[p] == '+')
     206        if (data[p] == '+')
    206207            ++p;
    207         else if (s[p] == '-') {
     208        else if (data[p] == '-') {
    208209            sign = -1;
    209210            ++p;
     
    211212    }
    212213
    213     if ((radix == 0 || radix == 16) && length - p >= 2 && s[p] == '0' && (s[p + 1] == 'x' || s[p + 1] == 'X')) {
     214    if ((radix == 0 || radix == 16) && length - p >= 2 && data[p] == '0' && (data[p + 1] == 'x' || data[p + 1] == 'X')) {
    214215        radix = 16;
    215216        p += 2;
    216217    } else if (radix == 0) {
    217         if (p < length && s[p] == '0')
     218        if (p < length && data[p] == '0')
    218219            radix = 8;
    219220        else
     
    228229    double number = 0;
    229230    while (p < length) {
    230         int digit = parseDigit(s[p], radix);
     231        int digit = parseDigit(data[p], radix);
    231232        if (digit == -1)
    232233            break;
     
    255256    // Need to skip any whitespace and then one + or - sign.
    256257    int length = s.size();
     258    const UChar* data = s.data();
    257259    int p = 0;
    258     while (p < length && isStrWhiteSpace(s[p]))
     260    while (p < length && isStrWhiteSpace(data[p]))
    259261        ++p;
    260262
    261     if (p < length && (s[p] == '+' || s[p] == '-'))
     263    if (p < length && (data[p] == '+' || data[p] == '-'))
    262264        ++p;
    263265
    264     if (length - p >= 2 && s[p] == '0' && (s[p + 1] == 'x' || s[p + 1] == 'X'))
     266    if (length - p >= 2 && data[p] == '0' && (data[p + 1] == 'x' || data[p + 1] == 'X'))
    265267        return 0;
    266268
Note: See TracChangeset for help on using the changeset viewer.