Branch: refs/heads/main
  Home:   https://github.com/WebKit/WebKit
  Commit: 7aeed1e3bd69527b49cf85957c5d53d0044fbd7a
      
https://github.com/WebKit/WebKit/commit/7aeed1e3bd69527b49cf85957c5d53d0044fbd7a
  Author: Sosuke Suzuki <[email protected]>
  Date:   2026-09-13 (Sun, 13 Sep 2026)

  Changed paths:
    A JSTests/microbenchmarks/string-replace-regexp-strip-prefix.js
    A JSTests/stress/string-replace-regexp-non-global-string-replacement.js
    M Source/JavaScriptCore/runtime/StringPrototypeInlines.h

  Log Message:
  -----------
  [JSC] Non-global `RegExp#replace` with an empty string should return a 
substring
https://bugs.webkit.org/show_bug.cgi?id=323409

Reviewed by Yusuke Suzuki.

`url.replace(/^https?:\/\//, "")` and similar idioms that strip a prefix or
a suffix copied the rest of the subject into a new StringImpl, so the cost
grew with the length of the string. The string-search version of replace
already returns substring cells for this.

When the replacement is empty and the match touches either end of the
subject, return a substring of the subject. Other cases keep the flat copy,
because a rope of several pieces is slower once it is resolved.

                                             Baseline                  Patched

string-replace-regexp-trim-end           16.5122+-0.2286     ?     
16.5982+-0.2722        ?
string-replace-regexp-trim-start         15.8060+-0.2518           
15.5517+-0.1634          might be 1.0163x faster
string-replace-regexp-strip-prefix       56.5716+-0.4533     ^     
24.6314+-0.1697        ^ definitely 2.2967x faster
string-replace-empty                      6.6183+-0.2257     ^      
6.2340+-0.1388        ^ definitely 1.0616x faster

Tests: JSTests/microbenchmarks/string-replace-regexp-strip-prefix.js
       JSTests/stress/string-replace-regexp-non-global-string-replacement.js

* JSTests/microbenchmarks/string-replace-regexp-strip-prefix.js: Added.
(test):
* JSTests/stress/string-replace-regexp-non-global-string-replacement.js: Added.
(shouldBe):
(replaceEmpty):
(replaceString):
* Source/JavaScriptCore/runtime/StringPrototypeInlines.h:
(JSC::replaceOneWithStringUsingRegExpSearch):

Canonical link: https://commits.webkit.org/321015@main



To unsubscribe from these emails, change your notification settings at 
https://github.com/WebKit/WebKit/settings/notifications

Reply via email to