From 6d7bca521b977fb08e4337b56d74e6ec8baad4c5 Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Thu, 16 Jul 2026 19:37:13 +0200 Subject: [PATCH] Use `Map.prototype.getOrInsertComputed` more in the `web/` folder --- web/internal/tree_view.js | 6 ++---- web/pdf_find_controller.js | 9 ++++----- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/web/internal/tree_view.js b/web/internal/tree_view.js index a227a9b83..b17645b58 100644 --- a/web/internal/tree_view.js +++ b/web/internal/tree_view.js @@ -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); diff --git a/web/pdf_find_controller.js b/web/pdf_find_controller.js index c0605b1b5..56187f236 100644 --- a/web/pdf_find_controller.js +++ b/web/pdf_find_controller.js @@ -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);