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

Unified Diff: src/harmony-string.js

Issue 832713009: Optimize String.prototype.includes Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 11 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/harmony-string.js
diff --git a/src/harmony-string.js b/src/harmony-string.js
index 6bbe139e87a3a2e96227799fea537261e9f87b51..b2c43ec6ef1660973a2f108e0b3ef196bdb4a6c5 100644
--- a/src/harmony-string.js
+++ b/src/harmony-string.js
@@ -98,28 +98,23 @@ 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("first_argument_not_regexp",
["String.prototype.includes"]);
}
- var ss = TO_STRING_INLINE(searchString);
- var pos = 0;
- if (%_ArgumentsLength() > 1) {
- pos = %_Arguments(1); // position
- pos = ToInteger(pos);
- }
+ var searchStr = TO_STRING_INLINE(searchString);
arv (Not doing code reviews) 2015/01/14 16:10:15 searchStr -> searchString
+ var pos = ToInteger(%_Arguments(1));
+ var len = string.length;
+ var searchLen = searchStr.length;
arv (Not doing code reviews) 2015/01/14 16:10:15 searchLen -> searchLength
- var s_len = s.length;
- var start = MathMin(MathMax(pos, 0), s_len);
- var ss_len = ss.length;
- if (ss_len + start > s_len) {
- return false;
- }
+ if (pos < 0) pos = 0;
+ if (pos > len) pos = len;
arv (Not doing code reviews) 2015/01/14 16:10:15 else if here?
+ if (searchLen + pos > len) return false;
- return %StringIndexOf(s, ss, start) !== -1;
+ return %StringIndexOf(string, searchStr, 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