mirror of
https://github.com/zen-browser/pdf.js.git
synced 2025-07-08 17:30:09 +02:00
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:
parent
a20393e6e4
commit
1491459dea
2 changed files with 20 additions and 4 deletions
|
@ -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];
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue