Chromium Code Reviews| Index: src/string.js |
| diff --git a/src/string.js b/src/string.js |
| index 3ddd6d26cedfd9e49a5e624e071f0caeb005fba7..be724f12cf77aa71758e257b7b925e7cf9424145 100644 |
| --- a/src/string.js |
| +++ b/src/string.js |
| @@ -1031,27 +1031,29 @@ function StringEndsWith(searchString /* position */) { // length == 1 |
| function StringIncludes(searchString /* position */) { // length == 1 |
| CHECK_OBJECT_COERCIBLE(this, "String.prototype.includes"); |
| - var s = TO_STRING_INLINE(this); |
| + var string = TO_STRING_INLINE(this); |
| if (IS_REGEXP(searchString)) { |
| throw MakeTypeError(kFirstArgumentNotRegExp, "String.prototype.includes"); |
| } |
| - var ss = TO_STRING_INLINE(searchString); |
| + searchString = TO_STRING_INLINE(searchString); |
|
thefourtheye_
2015/07/15 01:26:00
Isn't this a DEOPT? Using the argument variable in
|
| var pos = 0; |
| if (%_ArgumentsLength() > 1) { |
| pos = %_Arguments(1); // position |
| - pos = $toInteger(pos); |
| + pos = TO_INTEGER(pos); |
| } |
| - var s_len = s.length; |
| - var start = MathMin(MathMax(pos, 0), s_len); |
| - var ss_len = ss.length; |
| - if (ss_len + start > s_len) { |
| + var stringLength = string.length; |
| + if (pos < 0) pos = 0; |
| + if (pos > stringLength) pos = stringLength; |
| + var searchStringLength = searchString.length; |
|
thefourtheye_
2015/07/15 01:26:00
Very minor optimization, but can we move this abov
|
| + |
| + if (searchStringLength + pos > stringLength) { |
| return false; |
| } |
| - return %StringIndexOf(s, ss, start) !== -1; |
| + return %StringIndexOf(string, searchString, pos) !== -1; |
| } |