From 40d3916f3110343e1b9db67455e28d49c19856f5 Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Fri, 16 Aug 2019 13:47:12 +0200 Subject: [PATCH] Reduce the number of temporary variables in the `Parser.getObj` method This avoids allocating approximately 1.7 million short-lived variables when loading the PDF file from issue 2618, i.e. http://bugzilla-attachments.gnome.org/attachment.cgi?id=226471, in the default viewer. --- src/core/parser.js | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/core/parser.js b/src/core/parser.js index 8c895136e..176884296 100644 --- a/src/core/parser.js +++ b/src/core/parser.js @@ -89,7 +89,7 @@ class Parser { } } - getObj(cipherTransform) { + getObj(cipherTransform = null) { const buf1 = this.buf1; this.shift(); @@ -147,22 +147,20 @@ class Parser { } if (Number.isInteger(buf1)) { // indirect reference or integer - const num = buf1; if (Number.isInteger(this.buf1) && isCmd(this.buf2, 'R')) { - const ref = Ref.get(num, this.buf1); + const ref = Ref.get(buf1, this.buf1); this.shift(); this.shift(); return ref; } - return num; + return buf1; } if (typeof buf1 === 'string') { - let str = buf1; if (cipherTransform) { - str = cipherTransform.decryptString(str); + return cipherTransform.decryptString(buf1); } - return str; + return buf1; } // simple object