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…";
childrenEl.append(spinner);
this.#onMarkLoading(1);
if (!this.#refCache.has(cacheKey)) {
this.#refCache.set(cacheKey, doc.getRawData({ ref }));
}
this.#refCache
.get(cacheKey)
.getOrInsertComputed(cacheKey, () => doc.getRawData({ ref }))
.then(result => {
childrenEl.replaceChildren();
this.#buildChildren(result, doc, childrenEl);

View File

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