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

Unified Diff: src/string.js

Issue 1231673008: Optimize String.prototype.includes (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Changes from Adam's review Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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;
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698