⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 101186 in webkit


Ignore:
Timestamp:
Nov 25, 2011, 10:01:06 PM (15 years ago)
Author:
msaboff@apple.com
Message:

Array.toString always uses StringImpl::characters()
https://bugs.webkit.org/show_bug.cgi?id=72969

If all component strings are 8 bit, create an 8 bit result string for toString().

This appears to be performance neutral to sunspider and v8.

Reviewed by Filip Pizlo.

  • runtime/ArrayPrototype.cpp:

(JSC::arrayProtoFuncToString):

Location:
trunk/Source/JavaScriptCore
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/ChangeLog

    r101152 r101186  
     12011-11-25  Michael Saboff  <msaboff@apple.com>
     2
     3        Array.toString always uses StringImpl::characters()
     4        https://bugs.webkit.org/show_bug.cgi?id=72969
     5
     6        If all component strings are 8 bit, create an 8 bit result string for toString().
     7
     8        This appears to be performance neutral to sunspider and v8.
     9
     10        Reviewed by Filip Pizlo.
     11
     12        * runtime/ArrayPrototype.cpp:
     13        (JSC::arrayProtoFuncToString):
     14
    1152011-11-24  Michael Saboff  <msaboff@apple.com>
    216
  • trunk/Source/JavaScriptCore/runtime/ArrayPrototype.cpp

    r100006 r101186  
    186186    unsigned totalSize = length ? length - 1 : 0;
    187187    Vector<RefPtr<StringImpl>, 256> strBuffer(length);
     188    bool allStrings8Bit = true;
    188189
    189190    for (unsigned k = 0; k < length; k++) {
     
    200201        strBuffer[k] = str.impl();
    201202        totalSize += str.length();
     203        allStrings8Bit = allStrings8Bit && str.is8Bit();
    202204       
    203205        if (!strBuffer.data()) {
     
    210212    if (!totalSize)
    211213        return JSValue::encode(jsEmptyString(exec));
     214
     215    if (allStrings8Bit) {
     216        Vector<LChar> buffer;
     217        buffer.reserveCapacity(totalSize);
     218        if (!buffer.data())
     219            return JSValue::encode(throwOutOfMemoryError(exec));
     220       
     221        for (unsigned i = 0; i < length; i++) {
     222            if (i)
     223                buffer.append(',');
     224            if (RefPtr<StringImpl> rep = strBuffer[i])
     225                buffer.append(rep->characters8(), rep->length());
     226        }
     227        ASSERT(buffer.size() == totalSize);
     228        return JSValue::encode(jsString(exec, UString::adopt(buffer)));       
     229    }
     230
    212231    Vector<UChar> buffer;
    213232    buffer.reserveCapacity(totalSize);
Note: See TracChangeset for help on using the changeset viewer.