Skip to content

Commit

Permalink
Inline a couple of isRef/isDict checks in the getPageDict method
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Snuffleupagus committed Nov 8, 2019
1 parent 0d89006 commit 79d7c00
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/core/obj.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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
Expand All @@ -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.');
}
Expand Down

0 comments on commit 79d7c00

Please sign in to comment.