Skip to content

Commit c2f5e19

Browse files
committed
Use Map.prototype.getOrInsertComputed() in the src/core/xfa/ folder
1 parent 909a700 commit c2f5e19

3 files changed

Lines changed: 7 additions & 19 deletions

File tree

src/core/xfa/builder.js

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -166,12 +166,7 @@ class Builder {
166166
_addNamespacePrefix(prefixes) {
167167
for (const { prefix, value } of prefixes) {
168168
const namespace = this._searchNamespace(value);
169-
let prefixStack = this._namespacePrefixes.get(prefix);
170-
if (!prefixStack) {
171-
prefixStack = [];
172-
this._namespacePrefixes.set(prefix, prefixStack);
173-
}
174-
prefixStack.push(namespace);
169+
this._namespacePrefixes.getOrInsert(prefix, []).push(namespace);
175170
}
176171
}
177172

src/core/xfa/fonts.js

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,11 @@ class FontFinder {
4848
addPdfFont(pdfFont) {
4949
const cssFontInfo = pdfFont.cssFontInfo;
5050
const name = cssFontInfo.fontFamily;
51-
let font = this.fonts.get(name);
52-
if (!font) {
53-
font = Object.create(null);
54-
this.fonts.set(name, font);
55-
if (!this.defaultFont) {
56-
this.defaultFont = font;
57-
}
58-
}
51+
const font = this.fonts.getOrInsertComputed(name, () =>
52+
Object.create(null)
53+
);
54+
this.defaultFont ??= font;
55+
5956
let property = "";
6057
const fontWeight = parseFloat(cssFontInfo.fontWeight);
6158
if (parseFloat(cssFontInfo.italicAngle) !== 0) {

src/core/xfa/som.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -193,11 +193,7 @@ function searchNode(
193193
let children, cached;
194194

195195
if (useCache) {
196-
cached = somCache.get(node);
197-
if (!cached) {
198-
cached = new Map();
199-
somCache.set(node, cached);
200-
}
196+
cached = somCache.getOrInsertComputed(node, () => new Map());
201197
children = cached.get(cacheName);
202198
}
203199

0 commit comments

Comments
 (0)