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

Side by Side Diff: src/string.js

Issue 778005: Optimize fromCharCode for smi argument(s) case. (Closed)
Patch Set: Created 10 years, 9 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
« 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 2006-2009 the V8 project authors. All rights reserved. 1 // Copyright 2006-2009 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 701 matching lines...) Expand 10 before | Expand all | Expand 10 after
712 } 712 }
713 713
714 function StringTrimLeft() { 714 function StringTrimLeft() {
715 return %StringTrim(TO_STRING_INLINE(this), true, false); 715 return %StringTrim(TO_STRING_INLINE(this), true, false);
716 } 716 }
717 717
718 function StringTrimRight() { 718 function StringTrimRight() {
719 return %StringTrim(TO_STRING_INLINE(this), false, true); 719 return %StringTrim(TO_STRING_INLINE(this), false, true);
720 } 720 }
721 721
722 var static_charcode_array = new $Array(4);
723
722 // ECMA-262, section 15.5.3.2 724 // ECMA-262, section 15.5.3.2
723 function StringFromCharCode(code) { 725 function StringFromCharCode(code) {
724 var n = %_ArgumentsLength(); 726 var n = %_ArgumentsLength();
725 if (n == 1) return %_CharFromCode(ToNumber(code) & 0xffff) 727 if (n == 1) {
728 if (!%_IsSmi(code)) code = ToNumber(code);
729 return %_CharFromCode(code & 0xffff);
730 }
726 731
727 // NOTE: This is not super-efficient, but it is necessary because we 732 // NOTE: This is not super-efficient, but it is necessary because we
728 // want to avoid converting to numbers from within the virtual 733 // want to avoid converting to numbers from within the virtual
729 // machine. Maybe we can find another way of doing this? 734 // machine. Maybe we can find another way of doing this?
730 var codes = new $Array(n); 735 var codes = static_charcode_array;
731 for (var i = 0; i < n; i++) codes[i] = ToNumber(%_Arguments(i)); 736 for (var i = 0; i < n; i++) {
737 var code = %_Arguments(i);
738 if (!%_IsSmi(code)) code = ToNumber(code);
739 codes[i] = code;
740 }
741 codes.length = n;
732 return %StringFromCharCodeArray(codes); 742 return %StringFromCharCodeArray(codes);
733 } 743 }
734 744
735 745
736 // Helper function for very basic XSS protection. 746 // Helper function for very basic XSS protection.
737 function HtmlEscape(str) { 747 function HtmlEscape(str) {
738 return TO_STRING_INLINE(str).replace(/</g, "&lt;") 748 return TO_STRING_INLINE(str).replace(/</g, "&lt;")
739 .replace(/>/g, "&gt;") 749 .replace(/>/g, "&gt;")
740 .replace(/"/g, "&quot;") 750 .replace(/"/g, "&quot;")
741 .replace(/'/g, "&#039;"); 751 .replace(/'/g, "&#039;");
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
900 "small", StringSmall, 910 "small", StringSmall,
901 "strike", StringStrike, 911 "strike", StringStrike,
902 "sub", StringSub, 912 "sub", StringSub,
903 "sup", StringSup, 913 "sup", StringSup,
904 "toJSON", StringToJSON 914 "toJSON", StringToJSON
905 )); 915 ));
906 } 916 }
907 917
908 918
909 SetupString(); 919 SetupString();
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698