Skip to content

Commit 1c80412

Browse files
committed
Change PDFDocument.prototype._xfaStreams to return a Map
Using a `Map` rather than an `Object` is a nicer, since it has better support for both iteration and checking if a key exists. We also change the initial values to be `null`, rather than empty strings, and reduce duplication when creating the `Map`. *Please note:* Since this is worker-thread code, these changes are "invisible" at the API-level.
1 parent 9c6e2e6 commit 1c80412

1 file changed

Lines changed: 18 additions & 16 deletions

File tree

src/core/document.js

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1117,24 +1117,26 @@ class PDFDocument {
11171117
}
11181118

11191119
get _xfaStreams() {
1120-
const acroForm = this.catalog.acroForm;
1120+
const { acroForm } = this.catalog;
11211121
if (!acroForm) {
11221122
return null;
11231123
}
11241124

11251125
const xfa = acroForm.get("XFA");
1126-
const entries = {
1127-
"xdp:xdp": "",
1128-
template: "",
1129-
datasets: "",
1130-
config: "",
1131-
connectionSet: "",
1132-
localeSet: "",
1133-
stylesheet: "",
1134-
"/xdp:xdp": "",
1135-
};
1126+
const entries = new Map(
1127+
[
1128+
"xdp:xdp",
1129+
"template",
1130+
"datasets",
1131+
"config",
1132+
"connectionSet",
1133+
"localeSet",
1134+
"stylesheet",
1135+
"/xdp:xdp",
1136+
].map(e => [e, null])
1137+
);
11361138
if (xfa instanceof BaseStream && !xfa.isEmpty) {
1137-
entries["xdp:xdp"] = xfa;
1139+
entries.set("xdp:xdp", xfa);
11381140
return entries;
11391141
}
11401142

@@ -1152,14 +1154,14 @@ class PDFDocument {
11521154
name = xfa[i];
11531155
}
11541156

1155-
if (!entries.hasOwnProperty(name)) {
1157+
if (!entries.has(name)) {
11561158
continue;
11571159
}
11581160
const data = this.xref.fetchIfRef(xfa[i + 1]);
11591161
if (!(data instanceof BaseStream) || data.isEmpty) {
11601162
continue;
11611163
}
1162-
entries[name] = data;
1164+
entries.set(name, data);
11631165
}
11641166
return entries;
11651167
}
@@ -1170,7 +1172,7 @@ class PDFDocument {
11701172
return shadow(this, "xfaDatasets", null);
11711173
}
11721174
for (const key of ["datasets", "xdp:xdp"]) {
1173-
const stream = streams[key];
1175+
const stream = streams.get(key);
11741176
if (!stream) {
11751177
continue;
11761178
}
@@ -1192,7 +1194,7 @@ class PDFDocument {
11921194
return null;
11931195
}
11941196
const data = Object.create(null);
1195-
for (const [key, stream] of Object.entries(streams)) {
1197+
for (const [key, stream] of streams) {
11961198
if (!stream) {
11971199
continue;
11981200
}

0 commit comments

Comments
 (0)