Commit 84b4e1d4 authored by rossberg's avatar rossberg Committed by Commit bot

Revert "[es6] Optimize String{Starts, Ends}With"

This reverts commit b7db5cd9
(https://codereview.chromium.org/1324353002/).

Our internal dashboard shows that this patch has introduced massive (3x) performance regressions for string ops. This is probably due to it repeatedly invoking %_StringCharCodeAt in a loop, which is far from cheap (has to dispatch on one of our 30+ string representations each time).

TBR=dehrenberg@chromium.org
BUG=

Review URL: https://codereview.chromium.org/1439083003

Cr-Commit-Position: refs/heads/master@{#31981}
parent 138eb324
......@@ -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) {
return false;
}
for (var i = 0; i < ss_len; i++) {
if (%_StringCharCodeAt(s, pos + i) !== %_StringCharCodeAt(ss, i)) {
var start = end - ss_len;
if (start < 0) {
return false;
}
}
return true;
return %_SubString(s, start, start + ss_len) === ss;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment