Changeset 184866 in webkit for trunk/Source/JavaScriptCore


Ignore:
Timestamp:
May 26, 2015, 11:56:42 AM (10 years ago)
Author:
[email protected]
Message:

String.prototype.charCodeAt() should use StringView.
<https://webkit.org/b/145353>

Reviewed by Darin Adler.

Use JSString::view() in charCodeAt() to avoid reifying the JSString if it's
a substring. This avoids StringImpl allocation in some cases and ref churn
in all cases.

  • runtime/StringPrototype.cpp:

(JSC::stringProtoFuncCharCodeAt):

Location:
trunk/Source/JavaScriptCore
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/ChangeLog

    r184865 r184866  
     12015-05-26  Andreas Kling  <[email protected]>
     2
     3        String.prototype.charCodeAt() should use StringView.
     4        <https://webkit.org/b/145353>
     5
     6        Reviewed by Darin Adler.
     7
     8        Use JSString::view() in charCodeAt() to avoid reifying the JSString if it's
     9        a substring. This avoids StringImpl allocation in some cases and ref churn
     10        in all cases.
     11
     12        * runtime/StringPrototype.cpp:
     13        (JSC::stringProtoFuncCharCodeAt):
     14
    1152015-05-26  Andreas Kling  <[email protected]>
    216
  • trunk/Source/JavaScriptCore/runtime/StringPrototype.cpp

    r184865 r184866  
    805805    if (!checkObjectCoercible(thisValue))
    806806        return throwVMTypeError(exec);
    807     String s = thisValue.toString(exec)->value(exec);
    808     unsigned len = s.length();
     807    StringView string = thisValue.toString(exec)->view(exec);
    809808    JSValue a0 = exec->argument(0);
    810809    if (a0.isUInt32()) {
    811810        uint32_t i = a0.asUInt32();
    812         if (i < len) {
    813             if (s.is8Bit())
    814                 return JSValue::encode(jsNumber(s.characters8()[i]));
    815             return JSValue::encode(jsNumber(s.characters16()[i]));
    816         }
     811        if (i < string.length())
     812            return JSValue::encode(jsNumber(string[i]));
    817813        return JSValue::encode(jsNaN());
    818814    }
    819815    double dpos = a0.toInteger(exec);
    820     if (dpos >= 0 && dpos < len)
    821         return JSValue::encode(jsNumber(s[static_cast<int>(dpos)]));
     816    if (dpos >= 0 && dpos < string.length())
     817        return JSValue::encode(jsNumber(string[static_cast<int>(dpos)]));
    822818    return JSValue::encode(jsNaN());
    823819}
Note: See TracChangeset for help on using the changeset viewer.