Merge pull request #21586 from Snuffleupagus/web-more-getOrInsertComputed

Use `Map.prototype.getOrInsertComputed` more in the `web/` folder
This commit is contained in:
Tim van der Meij 2026-07-16 20:32:34 +02:00 committed by GitHub
commit 16290afa3b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
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);