Use Map.prototype.getOrInsertComputed more in the web/ folder

This commit is contained in:
Jonas Jenwald 2026-07-16 19:37:13 +02:00
parent 6e18a52b86
commit 6d7bca521b
2 changed files with 6 additions and 9 deletions

View File

@ -733,11 +733,9 @@ class TreeView {
spinner.textContent = "Loading…"; spinner.textContent = "Loading…";
childrenEl.append(spinner); childrenEl.append(spinner);
this.#onMarkLoading(1); this.#onMarkLoading(1);
if (!this.#refCache.has(cacheKey)) {
this.#refCache.set(cacheKey, doc.getRawData({ ref }));
}
this.#refCache this.#refCache
.get(cacheKey) .getOrInsertComputed(cacheKey, () => doc.getRawData({ ref }))
.then(result => { .then(result => {
childrenEl.replaceChildren(); childrenEl.replaceChildren();
this.#buildChildren(result, doc, childrenEl); this.#buildChildren(result, doc, childrenEl);

View File

@ -217,11 +217,10 @@ function normalize(text, options = {}) {
if (p2) { if (p2) {
// Use the NFKC representation to normalize the char. // Use the NFKC representation to normalize the char.
let replacement = NFKC_CHARS_TO_NORMALIZE.get(p2); const replacement = NFKC_CHARS_TO_NORMALIZE.getOrInsertComputed(
if (!replacement) { p2,
replacement = p2.normalize("NFKC"); () => p2.normalize("NFKC")
NFKC_CHARS_TO_NORMALIZE.set(p2, replacement); );
}
const jj = replacement.length; const jj = replacement.length;
for (let j = 1; j < jj; j++) { for (let j = 1; j < jj; j++) {
positions.push(i - shift + j, shift - j); positions.push(i - shift + j, shift - j);