From 8770ca30144b0f33d94d2f3f754cff25cf339b7c Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Thu, 26 Mar 2020 12:49:20 +0100 Subject: [PATCH] Make the `decryptAscii` helper function, in `src/core/type1_parser.js`, slightly more efficient By slicing the Uint8Array directly, rather than using the prototype and a `call` invocation, the runtime of `decryptAscii` is decreased slightly (~30% based on quick logging). The `decryptAscii` function is still less efficient than `decrypt`, however ASCII encoded Type1 font programs are sufficiently rare that it probably doesn't matter much (we've only seen *two* examples, issue 4630 and 11740). --- src/core/type1_parser.js | 2 +- src/shared/compatibility.js | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/core/type1_parser.js b/src/core/type1_parser.js index 2b8bb659c..60c6b8506 100644 --- a/src/core/type1_parser.js +++ b/src/core/type1_parser.js @@ -437,7 +437,7 @@ var Type1Parser = (function Type1ParserClosure() { r = ((value + r) * c1 + c2) & ((1 << 16) - 1); } } - return Array.prototype.slice.call(decrypted, discardNumber, j); + return decrypted.slice(discardNumber, j); } function isSpecial(c) { diff --git a/src/shared/compatibility.js b/src/shared/compatibility.js index 93fee9bd1..7cd219fba 100644 --- a/src/shared/compatibility.js +++ b/src/shared/compatibility.js @@ -224,6 +224,15 @@ if ( Number.isInteger = require("core-js/es/number/is-integer.js"); })(); + // Provides support for TypedArray.prototype.slice in legacy browsers. + // Support: IE + (function checkTypedArraySlice() { + if (Uint8Array.prototype.slice) { + return; + } + require("core-js/es/typed-array/slice"); + })(); + // Support: IE, Safari<11, Chrome<63 (function checkPromise() { if (typeof PDFJSDev !== "undefined" && PDFJSDev.test("IMAGE_DECODERS")) {