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

Unified Diff: src/string.js

Issue 11348349: Improve array to string conversion. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 8 years 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 side-by-side diff with in-line comments
Download patch
« src/json-stringifier.h ('K') | « src/runtime.cc ('k') | src/uri.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/string.js
diff --git a/src/string.js b/src/string.js
index 6115930b6c8ff69568f425b8b996a821bc93cb87..b698a2af5ba351e584b3dc7143be044ffe82ba23 100644
--- a/src/string.js
+++ b/src/string.js
@@ -801,6 +801,13 @@ function StringTrimRight() {
var static_charcode_array = new InternalArray(4);
+
+function TruncateString(string, new_length) {
+ if (new_length == 0) return "";
+ return %TruncateString(string, new_length);
+}
+
+
// ECMA-262, section 15.5.3.2
function StringFromCharCode(code) {
var n = %_ArgumentsLength();
@@ -809,17 +816,24 @@ function StringFromCharCode(code) {
return %_StringCharFromCode(code & 0xffff);
}
- // NOTE: This is not super-efficient, but it is necessary because we
- // want to avoid converting to numbers from within the virtual
- // machine. Maybe we can find another way of doing this?
- var codes = static_charcode_array;
- for (var i = 0; i < n; i++) {
+ var one_byte = %NewString(n, true);
Toon Verwaest 2012/12/05 14:29:12 Can we have a javascript macro that indicates that
+ var i;
+ for (i = 0; i < n; i++) {
var code = %_Arguments(i);
- if (!%_IsSmi(code)) code = ToNumber(code);
- codes[i] = code;
+ if (!%_IsSmi(code)) code = ToNumber(code) & 0xffff;
+ if (code > 0x7f) break;
+ %_OneByteSeqStringSetChar(one_byte, i, code);
+ }
+ if (i == n) return one_byte;
+ one_byte = TruncateString(one_byte, i);
+
+ var two_byte = %NewString(n - i, false);
+ for (var j = 0; i < n; i++, j++) {
+ var code = %_Arguments(i);
+ if (!%_IsSmi(code)) code = ToNumber(code) & 0xffff;
+ %_TwoByteSeqStringSetChar(two_byte, j, code);
}
- codes.length = n;
- return %StringFromCharCodeArray(codes);
+ return one_byte + two_byte;
}
« src/json-stringifier.h ('K') | « src/runtime.cc ('k') | src/uri.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698