Skip to content

Commit 1f7581b

Browse files
committed
Shorten the PDFDocument.prototype.fieldObjects getter slightly
The effect is probably not even measurable, however this patch ever so slightly reduces the asynchronicity in the `fieldObjects` getter. These changes should be safe since: - We're inside of the `PDFDocument`-class and the `annotationGlobals`-getter, which will always return a (shadowed) Promise and won't throw `MissingDataException`s, can be accessed directly without going through the `BasePdfManager`-instance. - The `acroForm`-dictionary can be accessed through the `annotationGlobals`-data, removing the need to "manually" look it up and thus the need for using `Promise.all` here. - We can also lookup the /Fields-data, in the `acroForm`-dictionary, synchronously since the initial `formInfo.hasFields` check guarantees that it's available.
1 parent 6f05231 commit 1f7581b

File tree

1 file changed

+3
-6
lines changed

1 file changed

+3
-6
lines changed

src/core/document.js

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1871,20 +1871,17 @@ class PDFDocument {
18711871
if (!formInfo.hasFields) {
18721872
return null;
18731873
}
1874-
1875-
const [annotationGlobals, acroForm] = await Promise.all([
1876-
this.pdfManager.ensureDoc("annotationGlobals"),
1877-
this.pdfManager.ensureCatalog("acroForm"),
1878-
]);
1874+
const annotationGlobals = await this.annotationGlobals;
18791875
if (!annotationGlobals) {
18801876
return null;
18811877
}
1878+
const { acroForm } = annotationGlobals;
18821879

18831880
const visitedRefs = new RefSet();
18841881
const allFields = Object.create(null);
18851882
const fieldPromises = new Map();
18861883
const orphanFields = new RefSetCache();
1887-
for (const fieldRef of await acroForm.getAsync("Fields")) {
1884+
for (const fieldRef of acroForm.get("Fields")) {
18881885
await this.#collectFieldObjects(
18891886
"",
18901887
null,

0 commit comments

Comments
 (0)