[Pkg-javascript-commits] [pdf.js] 207/246: Right-size the array in getSampleArray().

David Prévot taffit at moszumanska.debian.org
Sun Sep 7 15:36:41 UTC 2014


This is an automated email from the git hooks/post-receive script.

taffit pushed a commit to branch master
in repository pdf.js.

commit bcc31b666f3073bda7811fa6cd3df52e9ef816b4
Author: Nicholas Nethercote <nnethercote at mozilla.com>
Date:   Mon Aug 11 21:26:09 2014 -0700

    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 296757d..d8b7af7 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;

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/pdf.js.git



More information about the Pkg-javascript-commits mailing list