Title: [184866] trunk/Source/_javascript_Core
Revision
184866
Author
[email protected]
Date
2015-05-26 11:56:42 -0700 (Tue, 26 May 2015)

Log 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):

Modified Paths

Diff

Modified: trunk/Source/_javascript_Core/ChangeLog (184865 => 184866)


--- trunk/Source/_javascript_Core/ChangeLog	2015-05-26 18:54:01 UTC (rev 184865)
+++ trunk/Source/_javascript_Core/ChangeLog	2015-05-26 18:56:42 UTC (rev 184866)
@@ -1,5 +1,19 @@
 2015-05-26  Andreas Kling  <[email protected]>
 
+        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):
+
+2015-05-26  Andreas Kling  <[email protected]>
+
         String.prototype.charAt() should use StringView.
         <https://webkit.org/b/145352>
 

Modified: trunk/Source/_javascript_Core/runtime/StringPrototype.cpp (184865 => 184866)


--- trunk/Source/_javascript_Core/runtime/StringPrototype.cpp	2015-05-26 18:54:01 UTC (rev 184865)
+++ trunk/Source/_javascript_Core/runtime/StringPrototype.cpp	2015-05-26 18:56:42 UTC (rev 184866)
@@ -804,21 +804,17 @@
     JSValue thisValue = exec->thisValue();
     if (!checkObjectCoercible(thisValue))
         return throwVMTypeError(exec);
-    String s = thisValue.toString(exec)->value(exec);
-    unsigned len = s.length();
+    StringView string = thisValue.toString(exec)->view(exec);
     JSValue a0 = exec->argument(0);
     if (a0.isUInt32()) {
         uint32_t i = a0.asUInt32();
-        if (i < len) {
-            if (s.is8Bit())
-                return JSValue::encode(jsNumber(s.characters8()[i]));
-            return JSValue::encode(jsNumber(s.characters16()[i]));
-        }
+        if (i < string.length())
+            return JSValue::encode(jsNumber(string[i]));
         return JSValue::encode(jsNaN());
     }
     double dpos = a0.toInteger(exec);
-    if (dpos >= 0 && dpos < len)
-        return JSValue::encode(jsNumber(s[static_cast<int>(dpos)]));
+    if (dpos >= 0 && dpos < string.length())
+        return JSValue::encode(jsNumber(string[static_cast<int>(dpos)]));
     return JSValue::encode(jsNaN());
 }
 
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to