Changeset 6360 in webkit for trunk/JavaScriptCore/kjs/nodes.cpp


Ignore:
Timestamp:
Apr 13, 2004, 7:33:59 PM (21 years ago)
Author:
mjs
Message:

Reviewed by Darin.

  • fixed <rdar://problem/3600695>: String manipulation in JavaScript 24fun test is very slow (slow)
  • fixed <rdar://problem/3600691>: Table generation test is really slow
  • fixed <rdar://problem/3600661>: 24fun date test is really slow

80% speedup on the string test, lesser speedups on the other two.

Two different optimizations here:

1) Avoid large overhead of scanning strings to see if they are all
ASCII before numeric conversion.

  • kjs/nodes.cpp: (AssignNode::evaluate): Don't convert to integer until we know for sure the operation will need it. Attempting to convert strings to numbers is a waste when they are being appended with +=.

2) Avoid huge cost of appending strings.

This is done by allowing multiple strings to share a buffer but
actually use different ranges of it. The first time a string is
appended to, we start leaving at least 10% extra space in the
buffer, so doing N appends to the same string takes O(log N)
mallocs instead of O(N).

  • kjs/identifier.cpp: (KJS::Identifier::equal): (KJS::Identifier::add):
  • kjs/ustring.cpp: (KJS::): (KJS::UCharReference::operator=): (KJS::UCharReference::ref): (KJS::UString::Rep::create): (KJS::UString::Rep::destroy): (KJS::UString::expandedSize): (KJS::UString::usedCapacity): (KJS::UString::expandCapacity): (KJS::UString::UString): (KJS::UString::null): (KJS::UString::append): (KJS::UString::operator=): (KJS::UString::toStrictUInt32): (KJS::UString::detach): (KJS::KJS::operator==):
  • kjs/ustring.h: (KJS::UString::Rep::data): (KJS::UString::Rep::hash):
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/kjs/nodes.cpp

    r6347 r6360  
    13711371    Value v2 = expr->evaluate(exec);
    13721372    KJS_CHECKEXCEPTIONVALUE
    1373     int i1 = v1.toInt32(exec);
    1374     int i2 = v2.toInt32(exec);
     1373    int i1;
     1374    int i2;
    13751375    unsigned int ui;
    13761376    switch (oper) {
     
    13881388      break;
    13891389    case OpLShift:
     1390      i1 = v1.toInt32(exec);
     1391      i2 = v2.toInt32(exec);
    13901392      v = Number(i1 <<= i2);
    13911393      break;
    13921394    case OpRShift:
     1395      i1 = v1.toInt32(exec);
     1396      i2 = v2.toInt32(exec);
    13931397      v = Number(i1 >>= i2);
    13941398      break;
    13951399    case OpURShift:
    13961400      ui = v1.toUInt32(exec);
     1401      i2 = v2.toInt32(exec);
    13971402      v = Number(ui >>= i2);
    13981403      break;
    13991404    case OpAndEq:
     1405      i1 = v1.toInt32(exec);
     1406      i2 = v2.toInt32(exec);
    14001407      v = Number(i1 &= i2);
    14011408      break;
    14021409    case OpXOrEq:
     1410      i1 = v1.toInt32(exec);
     1411      i2 = v2.toInt32(exec);
    14031412      v = Number(i1 ^= i2);
    14041413      break;
    14051414    case OpOrEq:
     1415      i1 = v1.toInt32(exec);
     1416      i2 = v2.toInt32(exec);
    14061417      v = Number(i1 |= i2);
    14071418      break;
Note: See TracChangeset for help on using the changeset viewer.