From 79d7c002de2295de821e9aa9150315f9aa7ee186 Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Fri, 8 Nov 2019 17:36:46 +0100 Subject: [PATCH] Inline a couple of `isRef`/`isDict` checks in the `getPageDict` method As we've seen in numerous other cases, avoiding unnecessary function calls is never a bad thing (even if the effect is probably tiny here). With these changes we also avoid potentially two back-to-back `isDict` checks when evaluating possible Page nodes, and can also no longer accidentally pick a dictionary with an incorrect /Type. --- src/core/obj.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/core/obj.js b/src/core/obj.js index 1c2f4d4c5..63ff8f7ed 100644 --- a/src/core/obj.js +++ b/src/core/obj.js @@ -687,7 +687,7 @@ class Catalog { while (nodesToVisit.length) { const currentNode = nodesToVisit.pop(); - if (isRef(currentNode)) { + if (currentNode instanceof Ref) { count = pageKidsCountCache.get(currentNode); // Skip nodes where the page can't be. if (count > 0 && currentPageIndex + count < pageIndex) { @@ -696,7 +696,8 @@ class Catalog { } const obj = await xref.fetchAsync(currentNode); - if (isDict(obj, 'Page') || (isDict(obj) && !obj.has('Kids'))) { + if ((obj instanceof Dict) && (isName(obj.get('Type'), 'Page') || + (!obj.has('Type') && !obj.has('Kids')))) { if (pageIndex === currentPageIndex) { // Cache the Page reference, since it can *greatly* improve // performance by reducing redundant lookups in long documents @@ -714,7 +715,7 @@ class Catalog { } // Must be a child page dictionary. - if (!isDict(currentNode)) { + if (!(currentNode instanceof Dict)) { throw new FormatError( 'Page dictionary kid reference points to wrong type of object.'); }