Skip to content

Commit

Permalink
Reduce the number of temporary variables in the Parser.getObj method
Browse files Browse the repository at this point in the history
This avoid 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.
  • Loading branch information
Snuffleupagus committed Aug 16, 2019
1 parent 7728a66 commit 5a3f1a9
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions src/core/parser.js
Expand Up @@ -89,7 +89,7 @@ class Parser {
}
}

getObj(cipherTransform) {
getObj(cipherTransform = false) {
const buf1 = this.buf1;
this.shift();

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 5a3f1a9

Please sign in to comment.