Chromium Code Reviews

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: simplify code Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff |
« no previous file with comments | « no previous file | no next file » | 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 763 matching lines...)
774 function StringFromCharCode(code) { 774 function StringFromCharCode(code) {
775 var n = %_ArgumentsLength(); 775 var n = %_ArgumentsLength();
776 if (n == 1) { 776 if (n == 1) {
777 if (!%_IsSmi(code)) code = TO_NUMBER(code); 777 if (!%_IsSmi(code)) code = TO_NUMBER(code);
778 return %_StringCharFromCode(code & 0xffff); 778 return %_StringCharFromCode(code & 0xffff);
779 } 779 }
780 780
781 var one_byte = %NewString(n, NEW_ONE_BYTE_STRING); 781 var one_byte = %NewString(n, NEW_ONE_BYTE_STRING);
782 var i; 782 var i;
783 for (i = 0; i < n; i++) { 783 for (i = 0; i < n; i++) {
784 var code = %_Arguments(i); 784 var 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; 785 if (code > 0xff) break;
788 %_OneByteSeqStringSetChar(i, code, one_byte); 786 %_OneByteSeqStringSetChar(i, code, one_byte);
789 } 787 }
790 if (i == n) return one_byte; 788 if (i == n) return one_byte;
791 one_byte = %TruncateString(one_byte, i); 789 one_byte = %TruncateString(one_byte, i);
792 790
793 var two_byte = %NewString(n - i, NEW_TWO_BYTE_STRING); 791 var two_byte = %NewString(n - i, NEW_TWO_BYTE_STRING);
794 for (var j = 0; i < n; i++, j++) { 792 for (var j = 0; i < n; i++, j++) {
795 var code = %_Arguments(i); 793 var code = %_Arguments(i);
796 if (!%_IsSmi(code)) code = TO_NUMBER(code) & 0xffff; 794 if (!%_IsSmi(code)) code = TO_NUMBER(code) & 0xffff;
Benedikt Meurer 2015/11/09 08:11:52 Nit: Please also fix this one.
797 %_TwoByteSeqStringSetChar(j, code, two_byte); 795 %_TwoByteSeqStringSetChar(j, code, two_byte);
798 } 796 }
799 return one_byte + two_byte; 797 return one_byte + two_byte;
800 } 798 }
801 799
802 800
803 // ES6 draft, revision 26 (2014-07-18), section B.2.3.2.1 801 // ES6 draft, revision 26 (2014-07-18), section B.2.3.2.1
804 function HtmlEscape(str) { 802 function HtmlEscape(str) {
805 return %_Call(StringReplace, TO_STRING(str), /"/g, "&quot;"); 803 return %_Call(StringReplace, TO_STRING(str), /"/g, "&quot;");
806 } 804 }
(...skipping 362 matching lines...)
1169 to.StringLastIndexOf = StringLastIndexOfJS; 1167 to.StringLastIndexOf = StringLastIndexOfJS;
1170 to.StringMatch = StringMatchJS; 1168 to.StringMatch = StringMatchJS;
1171 to.StringReplace = StringReplace; 1169 to.StringReplace = StringReplace;
1172 to.StringSlice = StringSlice; 1170 to.StringSlice = StringSlice;
1173 to.StringSplit = StringSplitJS; 1171 to.StringSplit = StringSplitJS;
1174 to.StringSubstr = StringSubstr; 1172 to.StringSubstr = StringSubstr;
1175 to.StringSubstring = StringSubstring; 1173 to.StringSubstring = StringSubstring;
1176 }); 1174 });
1177 1175
1178 }) 1176 })
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine