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.
This commit is contained in:
Jonas Jenwald 2019-11-08 17:36:46 +01:00
parent 0d89006bf1
commit 79d7c002de

View File

@ -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.');
}