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

Issue 7782028: Faster non-regexp global string.replace. (Closed)

Created:
9 years, 3 months ago by Yang
Modified:
9 years, 3 months ago
Reviewers:
Lasse Reichstein
CC:
v8-dev
Visibility:
Public.

Description

Faster non-regexp global string.replace. BUG=v8:1662 Committed: http://code.google.com/p/v8/source/detail?r=9180

Patch Set 1 #

Total comments: 7
Unified diffs Side-by-side diffs Delta from patch set Stats (+186 lines, -90 lines) Patch
M src/runtime.cc View 5 chunks +186 lines, -90 lines 7 comments Download

Messages

Total messages: 2 (0 generated)
Yang
Previous implementation of string.replace would call the chain RegExpImpl::Exec->RegExpImpl::AtomExec->SearchString including all the type checks, conversions, ...
9 years, 3 months ago (2011-09-07 13:33:40 UTC) #1
Lasse Reichstein
9 years, 3 months ago (2011-09-07 13:50:52 UTC) #2
LGTM.

Another possible optimization is to not find all the indices first, but do it
inline. It saves the intermediate data structure. In that case you don't know
the length of the resulting string, but it's often sufficient to allocate a
string at the end of newspace, and extend or crop it as needed.

At least in the case where the replacement's length is the same as the pattern's
length, you do know the exact length of the result before finding matches, but
specializing for just that case might be a little too specific.

http://codereview.chromium.org/7782028/diff/1/src/runtime.cc
File src/runtime.cc (right):

http://codereview.chromium.org/7782028/diff/1/src/runtime.cc#newcode2874
src/runtime.cc:2874: Handle<String> replacement = Handle<String>::null()) {
Don't use an optional argument, just pass the null-handle in the few cases where
we replace with the empty string.

http://codereview.chromium.org/7782028/diff/1/src/runtime.cc#newcode2881
src/runtime.cc:2881:
String::cast(pattern_regexp->DataAt(JSRegExp::kAtomPatternIndex));
Assert that the regexp is atomic.

http://codereview.chromium.org/7782028/diff/1/src/runtime.cc#newcode2906
src/runtime.cc:2906: String::WriteToFlat(*subject,
Would it be worth it to check that that subject_pos is actually less than
indices.at(i)? I.e, there is something to write.

http://codereview.chromium.org/7782028/diff/1/src/runtime.cc#newcode2911
src/runtime.cc:2911: // Replace match.
Move comment down one line.

Powered by Google App Engine
This is Rietveld 408576698