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

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

Issue 1427743008: Do not switch to two-byte string in String.fromCharCode if avoidable. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: also fix fast path 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 unified diff | Download patch
« no previous file with comments | « no previous file | test/mjsunit/regress/string-fromcharcode-sideeffect.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
(...skipping 755 matching lines...) Expand 10 before | Expand all | Expand 10 after
766 function StringTrimRight() { 766 function StringTrimRight() {
767 CHECK_OBJECT_COERCIBLE(this, "String.prototype.trimRight"); 767 CHECK_OBJECT_COERCIBLE(this, "String.prototype.trimRight");
768 768
769 return %StringTrim(TO_STRING(this), false, true); 769 return %StringTrim(TO_STRING(this), false, true);
770 } 770 }
771 771
772 772
773 // ECMA-262, section 15.5.3.2 773 // ECMA-262, section 15.5.3.2
774 function StringFromCharCode(code) { 774 function StringFromCharCode(code) {
775 var n = %_ArgumentsLength(); 775 var n = %_ArgumentsLength();
776 if (n == 1) { 776 if (n == 1) return %_StringCharFromCode(code & 0xffff);
777 if (!%_IsSmi(code)) code = TO_NUMBER(code);
778 return %_StringCharFromCode(code & 0xffff);
779 }
780 777
781 var one_byte = %NewString(n, NEW_ONE_BYTE_STRING); 778 var one_byte = %NewString(n, NEW_ONE_BYTE_STRING);
782 var i; 779 var i;
783 for (i = 0; i < n; i++) { 780 for (i = 0; i < n; i++) {
784 var code = %_Arguments(i); 781 code = %_Arguments(i) & 0xffff;
785 if (!%_IsSmi(code)) code = TO_NUMBER(code) & 0xffff;
786 if (code < 0) code = code & 0xffff;
787 if (code > 0xff) break; 782 if (code > 0xff) break;
788 %_OneByteSeqStringSetChar(i, code, one_byte); 783 %_OneByteSeqStringSetChar(i, code, one_byte);
789 } 784 }
790 if (i == n) return one_byte; 785 if (i == n) return one_byte;
791 one_byte = %TruncateString(one_byte, i); 786 one_byte = %TruncateString(one_byte, i);
792 787
793 var two_byte = %NewString(n - i, NEW_TWO_BYTE_STRING); 788 var two_byte = %NewString(n - i, NEW_TWO_BYTE_STRING);
794 for (var j = 0; i < n; i++, j++) { 789 %_TwoByteSeqStringSetChar(0, code, two_byte);
795 var code = %_Arguments(i); 790 i++;
796 if (!%_IsSmi(code)) code = TO_NUMBER(code) & 0xffff; 791 for (var j = 1; i < n; i++, j++) {
792 code = %_Arguments(i) & 0xffff;
797 %_TwoByteSeqStringSetChar(j, code, two_byte); 793 %_TwoByteSeqStringSetChar(j, code, two_byte);
798 } 794 }
799 return one_byte + two_byte; 795 return one_byte + two_byte;
800 } 796 }
801 797
802 798
803 // ES6 draft, revision 26 (2014-07-18), section B.2.3.2.1 799 // ES6 draft, revision 26 (2014-07-18), section B.2.3.2.1
804 function HtmlEscape(str) { 800 function HtmlEscape(str) {
805 return %_Call(StringReplace, TO_STRING(str), /"/g, "&quot;"); 801 return %_Call(StringReplace, TO_STRING(str), /"/g, "&quot;");
806 } 802 }
(...skipping 362 matching lines...) Expand 10 before | Expand all | Expand 10 after
1169 to.StringLastIndexOf = StringLastIndexOfJS; 1165 to.StringLastIndexOf = StringLastIndexOfJS;
1170 to.StringMatch = StringMatchJS; 1166 to.StringMatch = StringMatchJS;
1171 to.StringReplace = StringReplace; 1167 to.StringReplace = StringReplace;
1172 to.StringSlice = StringSlice; 1168 to.StringSlice = StringSlice;
1173 to.StringSplit = StringSplitJS; 1169 to.StringSplit = StringSplitJS;
1174 to.StringSubstr = StringSubstr; 1170 to.StringSubstr = StringSubstr;
1175 to.StringSubstring = StringSubstring; 1171 to.StringSubstring = StringSubstring;
1176 }); 1172 });
1177 1173
1178 }) 1174 })
OLDNEW
« no previous file with comments | « no previous file | test/mjsunit/regress/string-fromcharcode-sideeffect.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698