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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 the V8 project authors. All rights reserved. 1 // Copyright 2014 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 "use strict"; 5 "use strict";
6 6
7 // This file relies on the fact that the following declaration has been made 7 // This file relies on the fact that the following declaration has been made
8 // in runtime.js: 8 // in runtime.js:
9 // var $String = global.String; 9 // var $String = global.String;
10 // var $Array = global.Array; 10 // var $Array = global.Array;
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
91 } 91 }
92 92
93 return %StringLastIndexOf(s, ss, start) === start; 93 return %StringLastIndexOf(s, ss, start) === start;
94 } 94 }
95 95
96 96
97 // ES6 draft 04-05-14, section 21.1.3.6 97 // ES6 draft 04-05-14, section 21.1.3.6
98 function StringIncludes(searchString /* position */) { // length == 1 98 function StringIncludes(searchString /* position */) { // length == 1
99 CHECK_OBJECT_COERCIBLE(this, "String.prototype.includes"); 99 CHECK_OBJECT_COERCIBLE(this, "String.prototype.includes");
100 100
101 var s = TO_STRING_INLINE(this); 101 var string = TO_STRING_INLINE(this);
102 102
103 if (IS_REGEXP(searchString)) { 103 if (IS_REGEXP(searchString)) {
104 throw MakeTypeError("first_argument_not_regexp", 104 throw MakeTypeError("first_argument_not_regexp",
105 ["String.prototype.includes"]); 105 ["String.prototype.includes"]);
106 } 106 }
107 107
108 var ss = TO_STRING_INLINE(searchString); 108 searchString = TO_STRING_INLINE(searchString);
109 var pos = 0;
110 if (%_ArgumentsLength() > 1) {
111 pos = %_Arguments(1); // position
112 pos = ToInteger(pos);
113 }
114 109
115 var s_len = s.length; 110 var pos = ToInteger(%_Arguments(1));
116 var start = MathMin(MathMax(pos, 0), s_len); 111 var len = string.length;
117 var ss_len = ss.length; 112 var searchLength = searchString.length;
118 if (ss_len + start > s_len) {
119 return false;
120 }
121 113
122 return %StringIndexOf(s, ss, start) !== -1; 114 if (pos < 0) pos = 0;
115 else if (pos > len) pos = len;
116
117 if (searchLength + pos > len) return false;
118
119 return %StringIndexOf(string, searchString, pos) !== -1;
123 } 120 }
124 121
125 122
126 // ES6 Draft 05-22-2014, section 21.1.3.3 123 // ES6 Draft 05-22-2014, section 21.1.3.3
127 function StringCodePointAt(pos) { 124 function StringCodePointAt(pos) {
128 CHECK_OBJECT_COERCIBLE(this, "String.prototype.codePointAt"); 125 CHECK_OBJECT_COERCIBLE(this, "String.prototype.codePointAt");
129 126
130 var string = TO_STRING_INLINE(this); 127 var string = TO_STRING_INLINE(this);
131 var size = string.length; 128 var size = string.length;
132 pos = TO_INTEGER(pos); 129 pos = TO_INTEGER(pos);
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
185 InstallFunctions($String.prototype, DONT_ENUM, $Array( 182 InstallFunctions($String.prototype, DONT_ENUM, $Array(
186 "codePointAt", StringCodePointAt, 183 "codePointAt", StringCodePointAt,
187 "includes", StringIncludes, 184 "includes", StringIncludes,
188 "endsWith", StringEndsWith, 185 "endsWith", StringEndsWith,
189 "repeat", StringRepeat, 186 "repeat", StringRepeat,
190 "startsWith", StringStartsWith 187 "startsWith", StringStartsWith
191 )); 188 ));
192 } 189 }
193 190
194 ExtendStringPrototype(); 191 ExtendStringPrototype();
OLDNEW
« 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