From 0c8944535f5f68ddba33c260f706304a1228a231 Mon Sep 17 00:00:00 2001 From: Jesse Tane Date: Sat, 22 Aug 2015 06:55:43 -0400 Subject: [PATCH] revert to old binary slice --- index.js | 26 +++++--------------------- 1 file changed, 5 insertions(+), 21 deletions(-) diff --git a/index.js b/index.js index 486d21f..ba5eab0 100644 --- a/index.js +++ b/index.js @@ -705,30 +705,14 @@ function asciiSlice (buf, start, end) { return ret } -// Based on http://stackoverflow.com/a/22747272/680742, the browser with -// the lowest limit is Chrome, with 0x10000 args. -// We go 1 magnitude less, for safety -var MAX_ARGUMENTS_LENGTH = 0x1000 - function binarySlice (buf, start, end) { - var len = buf.length - end = Math.min(len, end) - - // TODO: verify, this is probably the average case - if (start === 0 && end === len && end <= MAX_ARGUMENTS_LENGTH) { - return String.fromCharCode.apply(String, buf) - } - - var res = '' - - // Decode in chunks to avoid "call stack size exceeded". - for (var i = start; i < end; i += MAX_ARGUMENTS_LENGTH) { - var chunkEnd = Math.min(i + MAX_ARGUMENTS_LENGTH, end) + var ret = '' + end = Math.min(buf.length, end) - res += String.fromCharCode.apply(String, buf.slice(i, chunkEnd)) + for (var i = start; i < end; i++) { + ret += String.fromCharCode(buf[i]) } - - return res + return ret } function hexSlice (buf, start, end) { -- 2.34.1