Avoid unnecessary parsing, in Page.GetStructTree, when no structTree is available (PR 13221 follow-up)

It's obviously (a bit) more efficient to return early in `Page.getStructTree`, rather than trying to first "parse" an *empty* structTree-root.

*Somehow I didn't think of this yesterday, but this feels like a much better solution overall; sorry about the churn here!*
This commit is contained in:
Jonas Jenwald 2021-04-12 08:52:35 +02:00
parent 0d2dd6c2fe
commit 9360c7cbdc
3 changed files with 10 additions and 14 deletions

View File

@ -454,7 +454,13 @@ class Page {
const structTreeRoot = await this.pdfManager.ensureCatalog( const structTreeRoot = await this.pdfManager.ensureCatalog(
"structTreeRoot" "structTreeRoot"
); );
return this.pdfManager.ensure(this, "_parseStructTree", [structTreeRoot]); if (!structTreeRoot) {
return null;
}
const structTree = await this.pdfManager.ensure(this, "_parseStructTree", [
structTreeRoot,
]);
return structTree.serializable;
} }
/** /**

View File

@ -328,10 +328,6 @@ class StructTreePage {
} }
nodeToSerializable(child, root); nodeToSerializable(child, root);
} }
if (root.children.length === 0) {
return null;
}
return root; return root;
} }
} }

View File

@ -743,15 +743,9 @@ class WorkerMessageHandler {
}); });
handler.on("GetStructTree", function wphGetStructTree(data) { handler.on("GetStructTree", function wphGetStructTree(data) {
const pageIndex = data.pageIndex; return pdfManager.getPage(data.pageIndex).then(function (page) {
return pdfManager return pdfManager.ensure(page, "getStructTree");
.getPage(pageIndex) });
.then(function (page) {
return pdfManager.ensure(page, "getStructTree");
})
.then(function (structTree) {
return structTree.serializable;
});
}); });
handler.on("FontFallback", function (data) { handler.on("FontFallback", function (data) {