Improve caching for the Catalog.getPageIndex method (PR 13319 follow-up)

This method is now being used a lot more, compared to when it's added, since it's now used together with scripting as part of the `PDFDocument.fieldObjects` parsing (called during viewer initialization).
For /Page Dictionaries that we've already parsed, the `pageIndex` corresponding to a particular Reference is already known and we're thus able to skip *all* parsing in the `Catalog.getPageIndex` method for those cases.
This commit is contained in:
Jonas Jenwald 2021-12-29 15:57:34 +01:00
parent a20393e6e4
commit 1491459dea
2 changed files with 20 additions and 4 deletions

View file

@ -1285,9 +1285,14 @@ class PDFDocument {
type = await xref.fetchAsync(type);
}
if (isName(type, "Page") || (!obj.has("Type") && !obj.has("Kids"))) {
if (ref && !catalog.pageKidsCountCache.has(ref)) {
if (!catalog.pageKidsCountCache.has(ref)) {
catalog.pageKidsCountCache.put(ref, 1); // Cache the Page reference.
}
// Help improve performance of the `Catalog.getPageIndex` method.
if (!catalog.pageIndexCache.has(ref)) {
catalog.pageIndexCache.put(ref, 0);
}
return [obj, ref];
}
}