From bcc31b666f3073bda7811fa6cd3df52e9ef816b4 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Mon, 11 Aug 2014 21:26:09 -0700 Subject: [PATCH] Right-size the array in getSampleArray(). This allows the JS engine to do a better job of allocating the right number of elements for the array, avoiding some resizings. For the PDF in #2504, this avoids 100s of MiBs of allocations in Firefox. --- src/core/function.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/core/function.js b/src/core/function.js index 296757dd8..d8b7af7d5 100644 --- a/src/core/function.js +++ b/src/core/function.js @@ -35,7 +35,7 @@ var PDFFunction = (function PDFFunctionClosure() { } length *= outputSize; - var array = []; + var array = new Array(length); var codeSize = 0; var codeBuf = 0; // 32 is a valid bps so shifting won't work @@ -50,7 +50,7 @@ var PDFFunction = (function PDFFunctionClosure() { codeSize += 8; } codeSize -= bps; - array.push((codeBuf >> codeSize) * sampleMul); + array[i] = (codeBuf >> codeSize) * sampleMul; codeBuf &= (1 << codeSize) - 1; } return array;