| 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;
|
| }
|
|
|
|
|
|
|