[JSC] jsSubstring() should have a fast path for 0..baseLength "substrings."
authorakling@apple.com <akling@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 17 Jun 2015 18:54:13 +0000 (18:54 +0000)
committerakling@apple.com <akling@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 17 Jun 2015 18:54:13 +0000 (18:54 +0000)
<https://webkit.org/b/146051>

Reviewed by Anders Carlsson.

If asked to make a substring that actually spans the entire base string,
have jsSubstring() just return the base instead of allocating a new JSString.

3% speed-up on Octane/regexp.

* runtime/JSString.h:
(JSC::jsSubstring):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@185659 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/JavaScriptCore/ChangeLog
Source/JavaScriptCore/runtime/JSString.h

index a2ce090..f0cfad9 100644 (file)
@@ -1,3 +1,18 @@
+2015-06-17  Andreas Kling  <akling@apple.com>
+
+        [JSC] jsSubstring() should have a fast path for 0..baseLength "substrings."
+        <https://webkit.org/b/146051>
+
+        Reviewed by Anders Carlsson.
+
+        If asked to make a substring that actually spans the entire base string,
+        have jsSubstring() just return the base instead of allocating a new JSString.
+
+        3% speed-up on Octane/regexp.
+
+        * runtime/JSString.h:
+        (JSC::jsSubstring):
+
 2015-06-16  Alex Christensen  <achristensen@webkit.org>
 
         32-bit build fix after r185640.
index f4df1e0..66a38b2 100644 (file)
@@ -528,6 +528,8 @@ inline JSString* jsSubstring(ExecState* exec, JSString* s, unsigned offset, unsi
     VM& vm = exec->vm();
     if (!length)
         return vm.smallStrings.emptyString();
+    if (!offset && length == s->length())
+        return s;
     return JSRopeString::create(*exec, *s, offset, length);
 }