Chromium Code Reviews| Index: src/regexp.js |
| diff --git a/src/regexp.js b/src/regexp.js |
| index d58ca2634bd03f313e1326ca2c5b5542dbb00139..b668cf8b78b154a98fb1383ca8d02be271de8530 100644 |
| --- a/src/regexp.js |
| +++ b/src/regexp.js |
| @@ -108,23 +108,25 @@ function DoRegExpExec(regexp, string, index) { |
| } |
| -function BuildResultFromMatchInfo(lastMatchInfo, s) { |
| - var numResults = NUMBER_OF_CAPTURES(lastMatchInfo) >> 1; |
| - var start = lastMatchInfo[CAPTURE0]; |
| - var end = lastMatchInfo[CAPTURE1]; |
| - var result = %_RegExpConstructResult(numResults, start, s); |
| - result[0] = %_SubString(s, start, end); |
| +// This is kind of performance sensitive, so we want to avoid unnecessary |
| +// type checks on inputs. But we also don't want to inline it several times |
| +// manually, so we use a macro :-) |
| +macro BuildResultFromMatchInfo(MATCHINFO, STRING) |
|
Yang
2014/05/16 13:39:09
I would use capital naming for the macro to make i
Jakob Kummerow
2014/05/16 13:43:04
Done.
|
| + var numResults = NUMBER_OF_CAPTURES(MATCHINFO) >> 1; |
| + var start = MATCHINFO[CAPTURE0]; |
| + var end = MATCHINFO[CAPTURE1]; |
| + var result = %_RegExpConstructResult(numResults, start, STRING); |
| + result[0] = %_SubString(STRING, start, end); |
| var j = REGEXP_FIRST_CAPTURE + 2; |
| for (var i = 1; i < numResults; i++) { |
| - start = lastMatchInfo[j++]; |
| + start = MATCHINFO[j++]; |
| if (start != -1) { |
| - end = lastMatchInfo[j]; |
| - result[i] = %_SubString(s, start, end); |
| + end = MATCHINFO[j]; |
| + result[i] = %_SubString(STRING, start, end); |
| } |
| j++; |
| } |
| - return result; |
| -} |
| +endmacro |
| function RegExpExecNoTests(regexp, string, start) { |
| @@ -132,7 +134,8 @@ function RegExpExecNoTests(regexp, string, start) { |
| var matchInfo = %_RegExpExec(regexp, string, start, lastMatchInfo); |
| if (matchInfo !== null) { |
| lastMatchInfoOverride = null; |
| - return BuildResultFromMatchInfo(matchInfo, string); |
| + BuildResultFromMatchInfo(matchInfo, string); |
| + return result; |
|
Yang
2014/05/16 13:39:09
Why not make this part of the macro and call it so
Jakob Kummerow
2014/05/16 13:43:04
Done.
|
| } |
| regexp.lastIndex = 0; |
| return null; |
| @@ -175,7 +178,8 @@ function RegExpExec(string) { |
| if (global) { |
| this.lastIndex = lastMatchInfo[CAPTURE1]; |
| } |
| - return BuildResultFromMatchInfo(matchIndices, string); |
| + BuildResultFromMatchInfo(matchIndices, string); |
| + return result; |
| } |