diff options
author | Alon Zakai <alonzakai@gmail.com> | 2013-03-18 18:47:36 -0700 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2013-03-18 18:47:36 -0700 |
commit | bfbdd4937cebaf4048fceaedd08f0e5fb87e663c (patch) | |
tree | bde84b1b230fa4c8c8e7f692d12c7799ccc61584 /src | |
parent | 9f5ddb1568a37054808ec6e8fe95b051cef927ca (diff) |
process in chunks in fast path in Pointer_stringify
Diffstat (limited to 'src')
-rw-r--r-- | src/preamble.js | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/src/preamble.js b/src/preamble.js index 13af4326..2cff440c 100644 --- a/src/preamble.js +++ b/src/preamble.js @@ -516,14 +516,23 @@ function Pointer_stringify(ptr, /* optional */ length) { } if (!length) length = i; + var ret = ''; + #if USE_TYPED_ARRAYS == 2 if (!hasUtf) { - return String.fromCharCode.apply(String, HEAPU8.subarray(ptr, ptr + length)); + var MAX_CHUNK = 1024; // split up into chunks, because .apply on a huge string can overflow the stack + var curr; + while (length > 0) { + curr = String.fromCharCode.apply(String, HEAPU8.subarray(ptr, ptr + Math.min(length, MAX_CHUNK))); + ret = ret ? ret + curr : curr; + ptr += MAX_CHUNK; + length -= MAX_CHUNK; + } + return ret; } #endif var utf8 = new Runtime.UTF8Processor(); - var ret = ''; for (i = 0; i < length; i++) { #if ASSERTIONS assert(ptr + i < TOTAL_MEMORY); |