[Pkg-javascript-commits] [pdf.js] 06/246: Optimize common cases in hexToStr().

David Prévot taffit at moszumanska.debian.org
Sun Sep 7 15:36:19 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 501446ccc48e4c9923ef7611ab07bb0a678f4639
Author: Nicholas Nethercote <nnethercote at mozilla.com>
Date:   Tue Jul 22 22:09:54 2014 -0700

    Optimize common cases in hexToStr().
    
    This avoids the creation of over two million array objects when viewing
    http://www.dynacw.co.jp/Portals/3/fontsamplepdf/sample_4942546800828.pdf,
    and reduces load time from 76 to 73 ms.
---
 src/core/cmap.js | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/src/core/cmap.js b/src/core/cmap.js
index 792c679..83c0d72 100644
--- a/src/core/cmap.js
+++ b/src/core/cmap.js
@@ -313,6 +313,14 @@ var BinaryCMapReader = (function BinaryCMapReaderClosure() {
   }
 
   function hexToStr(a, size) {
+    // This code is hot. Special-case some common values to avoid creating an
+    // object with subarray().
+    if (size == 1) {
+      return String.fromCharCode(a[0], a[1]);
+    }
+    if (size == 3) {
+      return String.fromCharCode(a[0], a[1], a[2], a[3]);
+    }
     return String.fromCharCode.apply(null, a.subarray(0, size + 1));
   }
 

-- 
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