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

Unified Diff: src/js/string.js

Issue 1439083003: Revert "[es6] Optimize String{Starts, Ends}With" (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 1 month 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/js/string.js
diff --git a/src/js/string.js b/src/js/string.js
index 8ff5b3c008f8fdbc3b79b1530072b026057b8925..489ff983f787c25b9800e969c3ba3ba45e317f33 100644
--- a/src/js/string.js
+++ b/src/js/string.js
@@ -17,6 +17,8 @@ var InternalArray = utils.InternalArray;
var InternalPackedArray = utils.InternalPackedArray;
var MakeRangeError;
var MakeTypeError;
+var MathMax;
+var MathMin;
var RegExpExec;
var RegExpExecNoTests;
var RegExpLastMatchInfo;
@@ -27,6 +29,8 @@ utils.Import(function(from) {
ArrayJoin = from.ArrayJoin;
MakeRangeError = from.MakeRangeError;
MakeTypeError = from.MakeTypeError;
+ MathMax = from.MathMax;
+ MathMin = from.MathMin;
RegExpExec = from.RegExpExec;
RegExpExecNoTests = from.RegExpExecNoTests;
RegExpLastMatchInfo = from.RegExpLastMatchInfo;
@@ -879,21 +883,13 @@ function StringStartsWith(searchString /* position */) { // length == 1
}
var s_len = s.length;
- if (pos < 0) pos = 0;
- if (pos > s_len) pos = s_len;
+ var start = MathMin(MathMax(pos, 0), s_len);
var ss_len = ss.length;
-
- if (ss_len + pos > s_len) {
+ if (ss_len + start > s_len) {
return false;
}
- for (var i = 0; i < ss_len; i++) {
- if (%_StringCharCodeAt(s, pos + i) !== %_StringCharCodeAt(ss, i)) {
- return false;
- }
- }
-
- return true;
+ return %_SubString(s, start, start + ss_len) === ss;
}
@@ -917,22 +913,14 @@ function StringEndsWith(searchString /* position */) { // length == 1
}
}
- if (pos < 0) pos = 0;
- if (pos > s_len) pos = s_len;
+ var end = MathMin(MathMax(pos, 0), s_len);
var ss_len = ss.length;
- pos = pos - ss_len;
-
- if (pos < 0) {
+ var start = end - ss_len;
+ if (start < 0) {
return false;
}
- for (var i = 0; i < ss_len; i++) {
- if (%_StringCharCodeAt(s, pos + i) !== %_StringCharCodeAt(ss, i)) {
- return false;
- }
- }
-
- return true;
+ return %_SubString(s, start, start + ss_len) === ss;
}
« 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