[Pkg-javascript-commits] [pdf.js] 176/414: Make type 1 font program decryption faster.

David Prévot taffit at moszumanska.debian.org
Tue Jun 28 17:12:19 UTC 2016


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

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

commit 02331f6e3350e389b1e55861525e40eabf038b55
Author: Brendan Dahl <brendan.dahl at gmail.com>
Date:   Thu Jan 28 13:25:52 2016 -0800

    Make type 1 font program decryption faster.
    
    Discard the values first so we don't have to slice the array.
---
 src/core/fonts.js | 16 +++++++++++-----
 1 file changed, 11 insertions(+), 5 deletions(-)

diff --git a/src/core/fonts.js b/src/core/fonts.js
index 292c884..2fb333d 100644
--- a/src/core/fonts.js
+++ b/src/core/fonts.js
@@ -5326,15 +5326,21 @@ var Type1Parser = (function Type1ParserClosure() {
   }
 
   function decrypt(data, key, discardNumber) {
-    var r = key | 0, c1 = 52845, c2 = 22719;
-    var count = data.length;
+    if (discardNumber >= data.length) {
+      return new Uint8Array(0);
+    }
+    var r = key | 0, c1 = 52845, c2 = 22719, i, j;
+    for (i = 0; i < discardNumber; i++) {
+      r = ((data[i] + r) * c1 + c2) & ((1 << 16) - 1);
+    }
+    var count = data.length - discardNumber;
     var decrypted = new Uint8Array(count);
-    for (var i = 0; i < count; i++) {
+    for (i = discardNumber, j = 0; j < count; i++, j++) {
       var value = data[i];
-      decrypted[i] = value ^ (r >> 8);
+      decrypted[j] = value ^ (r >> 8);
       r = ((value + r) * c1 + c2) & ((1 << 16) - 1);
     }
-    return Array.prototype.slice.call(decrypted, discardNumber);
+    return decrypted;
   }
 
   function decryptAscii(data, key, discardNumber) {

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