• jgruber's avatar
    [string] Add a fast path to String.p.replace · f4ba786d
    jgruber authored
    This adds a fast path to skip runtime calls to GetSubstitution when
    the replacer string does not contain a '$' char.
    
    Extended background:
    
    String.prototype.replace is (roughly) structured as follows:
    
    * Check if {searchValue} has a @@replace Symbol, and delegate to that if
      so. We currently implement efficient fast paths when {searchValue} is
      a String or a fast RegExp.
    * A specialized fast path for single-char {searchValue}, "long" subject
      string, and String {replaceValue} that do not contain '$' chars (yes,
      this fast path is very specialized).
    * Check for the location of the first match using StringIndexOf, and
      exit early if no match is found.
    * Finally build the return value, which is 'prefix + replacement +
      suffix', where replacement is either the result of calling {replaceValue}
      (if it is callable), or GetSubstitution(ToString({replaceValue}))
      otherwise.
    
    There's several spots that could be improved.
    
    StringIndexOf currently calls into C++ runtime for all but the simple
    1-byte, 1-char {searchValue} case. We need to finally add support for
    remaining cases.
    
    The runtime call to GetSubstitution can be skipped if the replacer
    string does not contain any '$' syntax. This CL handles that case.
    
    BUG=
    
    Review-Url: https://codereview.chromium.org/2813843002
    Cr-Commit-Position: refs/heads/master@{#44606}
    f4ba786d
Name
Last commit
Last update
benchmarks Loading commit data...
build_overrides Loading commit data...
docs Loading commit data...
gni Loading commit data...
gypfiles Loading commit data...
include Loading commit data...
infra Loading commit data...
samples Loading commit data...
src Loading commit data...
test Loading commit data...
testing Loading commit data...
third_party Loading commit data...
tools Loading commit data...
.clang-format Loading commit data...
.gitignore Loading commit data...
.gn Loading commit data...
.ycm_extra_conf.py Loading commit data...
AUTHORS Loading commit data...
BUILD.gn Loading commit data...
CODE_OF_CONDUCT.md Loading commit data...
ChangeLog Loading commit data...
DEPS Loading commit data...
LICENSE Loading commit data...
LICENSE.fdlibm Loading commit data...
LICENSE.strongtalk Loading commit data...
LICENSE.v8 Loading commit data...
LICENSE.valgrind Loading commit data...
Makefile Loading commit data...
Makefile.android Loading commit data...
OWNERS Loading commit data...
PRESUBMIT.py Loading commit data...
README.md Loading commit data...
WATCHLISTS Loading commit data...
codereview.settings Loading commit data...
snapshot_toolchain.gni Loading commit data...