Ignore:
Timestamp:
Apr 30, 2009, 2:15:36 AM (16 years ago)
Author:
[email protected]
Message:

2009-04-30 Maciej Stachowiak <[email protected]>

Reviewed by Alexey Proskuryakov.

  • speed up string concatenation by reorganizing some simple cases

0.7% SunSpider speedup

  • runtime/UString.cpp: (JSC::concatenate): Put fast case for appending a single character before the empty string special cases; streamline code a bit to delay computing values that are not needed in the fast path.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/runtime/UString.cpp

    r42988 r43048  
    619619
    620620    int aSize = a->size();
     621    int bSize = b->size();
    621622    int aOffset = a->offset;
    622     int bSize = b->size();
    623     int bOffset = b->offset;
    624     int length = aSize + bSize;
    625623
    626624    // possible cases:
     625
     626    UString::BaseString* aBase = a->baseString();
     627    if (bSize == 1 && aOffset + aSize == aBase->usedCapacity && aOffset + aSize < aBase->capacity) {
     628        // b is a single character (common fast case)
     629        ++aBase->usedCapacity;
     630        a->data()[aSize] = b->data()[0];
     631        return UString::Rep::create(a, 0, aSize + 1);
     632    }
    627633
    628634    // a is empty
     
    633639        return a;
    634640
    635     UString::BaseString* aBase = a->baseString();
    636     if (bSize == 1 && aOffset + aSize == aBase->usedCapacity && aOffset + length <= aBase->capacity) {
    637         // b is a single character (common fast case)
    638         aBase->usedCapacity = aOffset + length;
    639         a->data()[aSize] = b->data()[0];
    640         return UString::Rep::create(a, 0, length);
    641     }
     641    int bOffset = b->offset;
     642    int length = aSize + bSize;
    642643
    643644    UString::BaseString* bBase = b->baseString();
Note: See TracChangeset for help on using the changeset viewer.