Use Map.prototype.getOrInsertComputed() in the src/core/xfa/ folder

This commit is contained in:
Jonas Jenwald 2026-02-22 22:14:21 +01:00
parent 909a700afa
commit c2f5e19eb0
3 changed files with 7 additions and 19 deletions

View File

@ -166,12 +166,7 @@ class Builder {
_addNamespacePrefix(prefixes) {
for (const { prefix, value } of prefixes) {
const namespace = this._searchNamespace(value);
let prefixStack = this._namespacePrefixes.get(prefix);
if (!prefixStack) {
prefixStack = [];
this._namespacePrefixes.set(prefix, prefixStack);
}
prefixStack.push(namespace);
this._namespacePrefixes.getOrInsert(prefix, []).push(namespace);
}
}

View File

@ -48,14 +48,11 @@ class FontFinder {
addPdfFont(pdfFont) {
const cssFontInfo = pdfFont.cssFontInfo;
const name = cssFontInfo.fontFamily;
let font = this.fonts.get(name);
if (!font) {
font = Object.create(null);
this.fonts.set(name, font);
if (!this.defaultFont) {
this.defaultFont = font;
}
}
const font = this.fonts.getOrInsertComputed(name, () =>
Object.create(null)
);
this.defaultFont ??= font;
let property = "";
const fontWeight = parseFloat(cssFontInfo.fontWeight);
if (parseFloat(cssFontInfo.italicAngle) !== 0) {

View File

@ -193,11 +193,7 @@ function searchNode(
let children, cached;
if (useCache) {
cached = somCache.get(node);
if (!cached) {
cached = new Map();
somCache.set(node, cached);
}
cached = somCache.getOrInsertComputed(node, () => new Map());
children = cached.get(cacheName);
}