From fc0cd4a443ef9d1fe6fe828b4edac447e51305e9 Mon Sep 17 00:00:00 2001 From: Tim van der Meij Date: Mon, 5 Apr 2021 19:20:10 +0200 Subject: [PATCH 1/2] Convert the `startXRefParsedCache` variable, in `src/core/obj.js`, from an object to a set We only want to track XRef starting points instead of actual data, so using a set conveys that intention more clearly and is slightly more efficient. --- src/core/obj.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/core/obj.js b/src/core/obj.js index 93bcde59f..9456e85ad 100644 --- a/src/core/obj.js +++ b/src/core/obj.js @@ -1944,18 +1944,18 @@ var XRef = (function XRefClosure() { // Keep track of already parsed XRef tables, to prevent an infinite loop // when parsing corrupt PDF files where e.g. the /Prev entries create a // circular dependency between tables (fixes bug1393476.pdf). - const startXRefParsedCache = Object.create(null); + const startXRefParsedCache = new Set(); try { while (this.startXRefQueue.length) { var startXRef = this.startXRefQueue[0]; - if (startXRefParsedCache[startXRef]) { + if (startXRefParsedCache.has(startXRef)) { warn("readXRef - skipping XRef table since it was already parsed."); this.startXRefQueue.shift(); continue; } - startXRefParsedCache[startXRef] = true; + startXRefParsedCache.add(startXRef); stream.pos = startXRef + stream.start; From ff393d6e969865b07e1928cf60354dc8edd2b170 Mon Sep 17 00:00:00 2001 From: Tim van der Meij Date: Mon, 5 Apr 2021 19:30:25 +0200 Subject: [PATCH 2/2] Convert the `pendingFindMatches` member, in `web/pdf_find_controller.js`, from an object to a set We only want to track page numbers instead of actual data, so using a set conveys that intention more clearly and is slightly more efficient. --- web/pdf_find_controller.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/web/pdf_find_controller.js b/web/pdf_find_controller.js index bc99e1f61..7eeb01e65 100644 --- a/web/pdf_find_controller.js +++ b/web/pdf_find_controller.js @@ -249,7 +249,7 @@ class PDFFindController { this._pageDiffs = []; this._matchesCountTotal = 0; this._pagesToSearch = null; - this._pendingFindMatches = Object.create(null); + this._pendingFindMatches = new Set(); this._resumePageIdx = null; this._dirtyMatch = false; clearTimeout(this._findTimeout); @@ -600,12 +600,12 @@ class PDFFindController { for (let i = 0; i < numPages; i++) { // Start finding the matches as soon as the text is extracted. - if (this._pendingFindMatches[i] === true) { + if (this._pendingFindMatches.has(i)) { continue; } - this._pendingFindMatches[i] = true; + this._pendingFindMatches.add(i); this._extractTextPromises[i].then(pageIdx => { - delete this._pendingFindMatches[pageIdx]; + this._pendingFindMatches.delete(pageIdx); this._calculateMatch(pageIdx); }); }