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

Unified Diff: src/harmony-string.js

Issue 832713009: Optimize String.prototype.includes Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Optimize String.prototype.includes 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..073ecb14d7975e1dcc4cd8fb82ca619b167dc925 100644
--- a/src/harmony-string.js
+++ b/src/harmony-string.js
@@ -98,28 +98,25 @@ 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);
- }
+ searchString = TO_STRING_INLINE(searchString);
- 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;
- }
+ var pos = ToInteger(%_Arguments(1));
+ var len = string.length;
+ var searchLength = searchString.length;
+
+ if (pos < 0) pos = 0;
+ else if (pos > len) pos = len;
+
+ if (searchLength + pos > len) 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