Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(196)

Issue 2813843002: [string] Add a fast path to String.p.replace (Closed)

Created:
3 years, 8 months ago by jgruber
Modified:
3 years, 8 months ago
CC:
v8-reviews_googlegroups.com
Target Ref:
refs/heads/master
Project:
v8
Visibility:
Public.

Description

[string] Add a fast path to String.p.replace 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} Committed: https://chromium.googlesource.com/v8/v8/+/f4ba786de8c182db79c293697b81184df41c6344

Patch Set 1 #

Patch Set 2 : Don't scan twice #

Unified diffs Side-by-side diffs Delta from patch set Stats (+93 lines, -21 lines) Patch
M src/builtins/builtins-string-gen.cc View 1 6 chunks +71 lines, -15 lines 0 comments Download
M src/code-stub-assembler.h View 1 1 chunk +1 line, -0 lines 0 comments Download
M src/code-stub-assembler.cc View 1 1 chunk +7 lines, -0 lines 0 comments Download
M src/objects.h View 1 1 chunk +4 lines, -1 line 0 comments Download
M src/objects.cc View 1 2 chunks +5 lines, -2 lines 0 comments Download
M src/runtime/runtime.h View 1 1 chunk +1 line, -1 line 0 comments Download
M src/runtime/runtime-strings.cc View 1 2 chunks +4 lines, -2 lines 0 comments Download

Messages

Total messages: 18 (13 generated)
jgruber
3 years, 8 months ago (2017-04-11 10:49:24 UTC) #6
jgruber
Patchset 2 is a bit smarter: * avoids scanning replace_string twice by telling String::GetSubstitution where ...
3 years, 8 months ago (2017-04-11 12:24:37 UTC) #9
Igor Sheludko
lgtm
3 years, 8 months ago (2017-04-12 09:51:10 UTC) #13
commit-bot: I haz the power
CQ is trying da patch. Follow status at https://chromium-cq-status.appspot.com/v2/patch-status/codereview.chromium.org/2813843002/20001
3 years, 8 months ago (2017-04-12 10:39:24 UTC) #15
commit-bot: I haz the power
3 years, 8 months ago (2017-04-12 10:41:04 UTC) #18
Message was sent while issue was closed.
Committed patchset #2 (id:20001) as
https://chromium.googlesource.com/v8/v8/+/f4ba786de8c182db79c293697b81184df41...

Powered by Google App Engine
This is Rietveld 408576698