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

Side by Side Diff: src/js/string.js

Issue 1641083003: [builtins] Make Math.max and Math.min fast by default. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: SKIP unrelated ignition failures. Created 4 years, 10 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
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 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 (function(global, utils) { 5 (function(global, utils) {
6 6
7 %CheckIsBootstrapping(); 7 %CheckIsBootstrapping();
8 8
9 // ------------------------------------------------------------------- 9 // -------------------------------------------------------------------
10 // Imports 10 // Imports
11 11
12 var ArrayIndexOf; 12 var ArrayIndexOf;
13 var ArrayJoin; 13 var ArrayJoin;
14 var GlobalRegExp = global.RegExp; 14 var GlobalRegExp = global.RegExp;
15 var GlobalString = global.String; 15 var GlobalString = global.String;
16 var InternalArray = utils.InternalArray; 16 var InternalArray = utils.InternalArray;
17 var InternalPackedArray = utils.InternalPackedArray; 17 var InternalPackedArray = utils.InternalPackedArray;
18 var MakeRangeError; 18 var MakeRangeError;
19 var MakeTypeError; 19 var MakeTypeError;
20 var MathMax; 20 var MaxSimple;
21 var MathMin; 21 var MinSimple;
22 var matchSymbol = utils.ImportNow("match_symbol"); 22 var matchSymbol = utils.ImportNow("match_symbol");
23 var RegExpExecNoTests; 23 var RegExpExecNoTests;
24 var replaceSymbol = utils.ImportNow("replace_symbol"); 24 var replaceSymbol = utils.ImportNow("replace_symbol");
25 var searchSymbol = utils.ImportNow("search_symbol"); 25 var searchSymbol = utils.ImportNow("search_symbol");
26 var splitSymbol = utils.ImportNow("split_symbol"); 26 var splitSymbol = utils.ImportNow("split_symbol");
27 27
28 utils.Import(function(from) { 28 utils.Import(function(from) {
29 ArrayIndexOf = from.ArrayIndexOf; 29 ArrayIndexOf = from.ArrayIndexOf;
30 ArrayJoin = from.ArrayJoin; 30 ArrayJoin = from.ArrayJoin;
31 MakeRangeError = from.MakeRangeError; 31 MakeRangeError = from.MakeRangeError;
32 MakeTypeError = from.MakeTypeError; 32 MakeTypeError = from.MakeTypeError;
33 MathMax = from.MathMax; 33 MaxSimple = from.MaxSimple;
34 MathMin = from.MathMin; 34 MinSimple = from.MinSimple;
35 RegExpExecNoTests = from.RegExpExecNoTests; 35 RegExpExecNoTests = from.RegExpExecNoTests;
36 }); 36 });
37 37
38 //------------------------------------------------------------------- 38 //-------------------------------------------------------------------
39 39
40 // ECMA-262 section 15.5.4.2 40 // ECMA-262 section 15.5.4.2
41 function StringToString() { 41 function StringToString() {
42 if (!IS_STRING(this) && !IS_STRING_WRAPPER(this)) { 42 if (!IS_STRING(this) && !IS_STRING_WRAPPER(this)) {
43 throw MakeTypeError(kNotGeneric, 'String.prototype.toString'); 43 throw MakeTypeError(kNotGeneric, 'String.prototype.toString');
44 } 44 }
(...skipping 683 matching lines...) Expand 10 before | Expand all | Expand 10 after
728 var ss = TO_STRING(searchString); 728 var ss = TO_STRING(searchString);
729 var pos = 0; 729 var pos = 0;
730 if (%_ArgumentsLength() > 1) { 730 if (%_ArgumentsLength() > 1) {
731 var arg = %_Arguments(1); // position 731 var arg = %_Arguments(1); // position
732 if (!IS_UNDEFINED(arg)) { 732 if (!IS_UNDEFINED(arg)) {
733 pos = TO_INTEGER(arg); 733 pos = TO_INTEGER(arg);
734 } 734 }
735 } 735 }
736 736
737 var s_len = s.length; 737 var s_len = s.length;
738 var start = MathMin(MathMax(pos, 0), s_len); 738 var start = MinSimple(MaxSimple(pos, 0), s_len);
739 var ss_len = ss.length; 739 var ss_len = ss.length;
740 if (ss_len + start > s_len) { 740 if (ss_len + start > s_len) {
741 return false; 741 return false;
742 } 742 }
743 743
744 return %_SubString(s, start, start + ss_len) === ss; 744 return %_SubString(s, start, start + ss_len) === ss;
745 } 745 }
746 746
747 747
748 // ES6 draft 04-05-14, section 21.1.3.7 748 // ES6 draft 04-05-14, section 21.1.3.7
749 function StringEndsWith(searchString /* position */) { // length == 1 749 function StringEndsWith(searchString /* position */) { // length == 1
750 CHECK_OBJECT_COERCIBLE(this, "String.prototype.endsWith"); 750 CHECK_OBJECT_COERCIBLE(this, "String.prototype.endsWith");
751 751
752 var s = TO_STRING(this); 752 var s = TO_STRING(this);
753 753
754 if (IS_REGEXP(searchString)) { 754 if (IS_REGEXP(searchString)) {
755 throw MakeTypeError(kFirstArgumentNotRegExp, "String.prototype.endsWith"); 755 throw MakeTypeError(kFirstArgumentNotRegExp, "String.prototype.endsWith");
756 } 756 }
757 757
758 var ss = TO_STRING(searchString); 758 var ss = TO_STRING(searchString);
759 var s_len = s.length; 759 var s_len = s.length;
760 var pos = s_len; 760 var pos = s_len;
761 if (%_ArgumentsLength() > 1) { 761 if (%_ArgumentsLength() > 1) {
762 var arg = %_Arguments(1); // position 762 var arg = %_Arguments(1); // position
763 if (!IS_UNDEFINED(arg)) { 763 if (!IS_UNDEFINED(arg)) {
764 pos = TO_INTEGER(arg); 764 pos = TO_INTEGER(arg);
765 } 765 }
766 } 766 }
767 767
768 var end = MathMin(MathMax(pos, 0), s_len); 768 var end = MinSimple(MaxSimple(pos, 0), s_len);
769 var ss_len = ss.length; 769 var ss_len = ss.length;
770 var start = end - ss_len; 770 var start = end - ss_len;
771 if (start < 0) { 771 if (start < 0) {
772 return false; 772 return false;
773 } 773 }
774 774
775 return %_SubString(s, start, start + ss_len) === ss; 775 return %_SubString(s, start, start + ss_len) === ss;
776 } 776 }
777 777
778 778
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
950 to.StringLastIndexOf = StringLastIndexOfJS; 950 to.StringLastIndexOf = StringLastIndexOfJS;
951 to.StringMatch = StringMatchJS; 951 to.StringMatch = StringMatchJS;
952 to.StringReplace = StringReplace; 952 to.StringReplace = StringReplace;
953 to.StringSlice = StringSlice; 953 to.StringSlice = StringSlice;
954 to.StringSplit = StringSplitJS; 954 to.StringSplit = StringSplitJS;
955 to.StringSubstr = StringSubstr; 955 to.StringSubstr = StringSubstr;
956 to.StringSubstring = StringSubstring; 956 to.StringSubstring = StringSubstring;
957 }); 957 });
958 958
959 }) 959 })
OLDNEW
« src/arm64/builtins-arm64.cc ('K') | « src/js/prologue.js ('k') | src/mips/builtins-mips.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698