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

Issue 1109010: Run string replace regexp with function in C++ code loop. (Closed)

Created:
10 years, 9 months ago by Lasse Reichstein
Modified:
10 years, 9 months ago
Reviewers:
sandholm, fschneider
CC:
v8-dev
Visibility:
Public.

Description

Run string replace regexp with function in C++ code loop. Reuses the result array to save on allocation. Matches Safari's behavior.

Patch Set 1 #

Patch Set 2 : Fix to also work in debug mode. #

Total comments: 34
Unified diffs Side-by-side diffs Delta from patch set Stats (+710 lines, -118 lines) Patch
M src/jsregexp.h View 1 chunk +5 lines, -0 lines 2 comments Download
M src/regexp-delay.js View 5 chunks +38 lines, -7 lines 0 comments Download
M src/runtime.h View 1 chunk +1 line, -0 lines 0 comments Download
M src/runtime.cc View 1 10 chunks +593 lines, -36 lines 30 comments Download
M src/string.js View 2 chunks +73 lines, -75 lines 2 comments Download

Messages

Total messages: 4 (0 generated)
Lasse Reichstein
Largish review.
10 years, 9 months ago (2010-03-23 13:37:25 UTC) #1
Lasse Reichstein
Reallocate reviewer.
10 years, 9 months ago (2010-03-24 13:37:20 UTC) #2
fschneider
LGTM with a couple of suggestions and style comments. http://codereview.chromium.org/1109010/diff/3001/4001 File src/jsregexp.h (right): http://codereview.chromium.org/1109010/diff/3001/4001#newcode145 src/jsregexp.h:145: ...
10 years, 9 months ago (2010-03-25 10:26:06 UTC) #3
Lasse Reichstein
10 years, 9 months ago (2010-03-26 11:18:26 UTC) #4
http://codereview.chromium.org/1109010/diff/3001/4001
File src/jsregexp.h (right):

http://codereview.chromium.org/1109010/diff/3001/4001#newcode145
src/jsregexp.h:145: static bool IsAtom(FixedArray* array) {
I don't think so. I switched to using JSRegExp::IsAtom instead. 
Will remove.

http://codereview.chromium.org/1109010/diff/3001/4003
File src/runtime.cc (right):

http://codereview.chromium.org/1109010/diff/3001/4003#newcode1619
src/runtime.cc:1619: inline Handle<FixedArray> array() {
I think you are right. Inlining is default in this case.

http://codereview.chromium.org/1109010/diff/3001/4003#newcode1650
src/runtime.cc:1650: static const int kStringBuilderConcatHelperLengthBits = 11;
Fixed.

http://codereview.chromium.org/1109010/diff/3001/4003#newcode1659
src/runtime.cc:1659: typedef BitField<int, 0, 11> StringBuilderSubstringLength;
Very long, but changed anyway.

http://codereview.chromium.org/1109010/diff/3001/4003#newcode2953
src/runtime.cc:2953: static const int kMaxBuilderEntriesPerRegExpMatch = 5;
Removed.

http://codereview.chromium.org/1109010/diff/3001/4003#newcode2988
src/runtime.cc:2988: if (new_pos >= 0) {
I want to have the "fast case" as the first branch of the if.
I guess the compiler would generate the exact same code in both cases, though. 
I'll keep this for now.

http://codereview.chromium.org/1109010/diff/3001/4003#newcode3013
src/runtime.cc:3013: uc16 pattern_char = pattern->Get(0);
Not necessary. Get is generic and works on both kinds of strings, and always
return uc16.

http://codereview.chromium.org/1109010/diff/3001/4003#newcode3021
src/runtime.cc:3021: if (pattern_char > String::kMaxAsciiCharCode) {
How not?

http://codereview.chromium.org/1109010/diff/3001/4003#newcode3069
src/runtime.cc:3069: case SEARCH_SHORT: {
Done.

http://codereview.chromium.org/1109010/diff/3001/4003#newcode3078
src/runtime.cc:3078: if (new_pos >= 0) {
Same argument as last time, I want the "then" branch to be the fast case (the
one that keeps looping).

http://codereview.chromium.org/1109010/diff/3001/4003#newcode3093
src/runtime.cc:3093: case SEARCH_LONG: {
Done.

http://codereview.chromium.org/1109010/diff/3001/4003#newcode3102
src/runtime.cc:3102: if (new_pos >= 0) {
Also retained.

http://codereview.chromium.org/1109010/diff/3001/4003#newcode3312
src/runtime.cc:3312: Vector<int> tmp = prev_register_vector;
Vector is a two-value struct. Allocating a single stack-vector won't be faster
than allocating a new each time, it'll be at the same place on the stack anyway.

http://codereview.chromium.org/1109010/diff/3001/4003#newcode3384
src/runtime.cc:3384: if (pattern_length == 1) {
That wouldn't return null if SearchCharMultiple returns false.

http://codereview.chromium.org/1109010/diff/3001/4003#newcode3419
src/runtime.cc:3419: if (result == RegExpImpl::RE_SUCCESS) return
*builder.ToJSArray(result_array);
On 2010/03/25 10:26:06, fschneider wrote:
> The test for the result seems duplicated. You could write:
> 
> RegExpImpl::IrregexpResult result;
> if (capture_count == 0) {
>   result = SearchRegExpNoCaptureMultiple(...);
> } else {
>   result = SearchRegExpMultiple(...)'
> }
> if (result == RegExpImpl::RE_SUCCESS) return ...
> if (result == RegExpImpl::RE_FAILURE) return ...
> ASSERT_EQ(result, RegExpImpl::RE_EXCEPTION);
> return Failure::Exception();

Done.

http://codereview.chromium.org/1109010/diff/3001/4005
File src/string.js (right):

http://codereview.chromium.org/1109010/diff/3001/4005#newcode434
src/string.js:434: regexp.lastIndex = 0; // why this?
Removed. There is no doubt why if one reads the specification of
RegExp.prototype.replace :)

Powered by Google App Engine
This is Rietveld 408576698