From a4190061d96f0e6346c3133fa126d9f80810cc09 Mon Sep 17 00:00:00 2001 From: Bart Butler Date: Tue, 28 Mar 2017 10:35:20 -0700 Subject: [PATCH] optimize Uint8Array2str function for large payloads --- src/util.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/util.js b/src/util.js index b329d84b..a81d3eec 100644 --- a/src/util.js +++ b/src/util.js @@ -274,9 +274,12 @@ export default { throw new Error('Uint8Array2str: Data must be in the form of a Uint8Array'); } - var result = []; - for (var i = 0; i < bin.length; i++) { - result[i] = String.fromCharCode(bin[i]); + var result = [], + bs = 16384, + j = bin.length; + + for (var i = 0; i < j; i += bs) { + result.push(String.fromCharCode.apply(String, bin.slice(i, i+bs < j ? i+bs : j))); } return result.join(''); },