[Pkg-javascript-commits] [pdf.js] 141/246: Add IdentityToUnicodeMap class.

David Prévot taffit at moszumanska.debian.org
Sun Sep 7 15:36:34 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 6c8cca1284f061028bc5521b307d662ea831d0f0
Author: Nicholas Nethercote <nnethercote at mozilla.com>
Date:   Thu Aug 7 18:29:53 2014 -0700

    Add IdentityToUnicodeMap class.
    
    When loading the PDF from issue #4935, this change reduces peak RSS from
    ~2400 to ~300 MiB, and improves overall speed by ~81%, from 6336 ms to
    1222 ms.
---
 src/core/fonts.js | 40 ++++++++++++++++++++++++++++++++++------
 1 file changed, 34 insertions(+), 6 deletions(-)

diff --git a/src/core/fonts.js b/src/core/fonts.js
index e14ea35..dc63691 100644
--- a/src/core/fonts.js
+++ b/src/core/fonts.js
@@ -2191,6 +2191,38 @@ var ToUnicodeMap = (function ToUnicodeMapClosure() {
   return ToUnicodeMap;
 })();
 
+var IdentityToUnicodeMap = (function IdentityToUnicodeMapClosure() {
+  function IdentityToUnicodeMap(firstChar, lastChar) {
+    this.firstChar = firstChar;
+    this.lastChar = lastChar;
+  }
+
+  IdentityToUnicodeMap.prototype = {
+    get length() {
+      error('should not access .length');
+    },
+
+    forEach: function(callback) {
+      for (var i = this.firstChar, ii = this.lastChar; i <= ii; i++) {
+        callback(i, i);
+      }
+    },
+
+    get: function(i) {
+      if (this.firstChar <= i && i <= this.lastChar) {
+        return String.fromCharCode(i);
+      }
+      return undefined;
+    },
+
+    charCodeOf: function(v) {
+      error('should not call .charCodeOf');
+    }
+  };
+
+  return IdentityToUnicodeMap;
+})();
+
 /**
  * 'Font' is the class the outside world should use, it encapsulate all the font
  * decoding logics whatever type it is (assuming the font type is supported).
@@ -4453,13 +4485,9 @@ var Font = (function FontClosure() {
       }
 
       // The viewer's choice, just use an identity map.
-      toUnicode = [];
-      var firstChar = properties.firstChar, lastChar = properties.lastChar;
-      for (var i = firstChar; i <= lastChar; i++) {
-        toUnicode[i] = String.fromCharCode(i);
-      }
       map.isIdentity = true;
-      map.toUnicode = new ToUnicodeMap(toUnicode);
+      map.toUnicode =
+        new IdentityToUnicodeMap(properties.firstChar, properties.lastChar);
       return map;
     },
 

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