Skip to content

Commit 6d7bca5

Browse files
committed
Use Map.prototype.getOrInsertComputed more in the web/ folder
1 parent 6e18a52 commit 6d7bca5

2 files changed

Lines changed: 6 additions & 9 deletions

File tree

web/internal/tree_view.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -733,11 +733,9 @@ class TreeView {
733733
spinner.textContent = "Loading…";
734734
childrenEl.append(spinner);
735735
this.#onMarkLoading(1);
736-
if (!this.#refCache.has(cacheKey)) {
737-
this.#refCache.set(cacheKey, doc.getRawData({ ref }));
738-
}
736+
739737
this.#refCache
740-
.get(cacheKey)
738+
.getOrInsertComputed(cacheKey, () => doc.getRawData({ ref }))
741739
.then(result => {
742740
childrenEl.replaceChildren();
743741
this.#buildChildren(result, doc, childrenEl);

web/pdf_find_controller.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -217,11 +217,10 @@ function normalize(text, options = {}) {
217217

218218
if (p2) {
219219
// Use the NFKC representation to normalize the char.
220-
let replacement = NFKC_CHARS_TO_NORMALIZE.get(p2);
221-
if (!replacement) {
222-
replacement = p2.normalize("NFKC");
223-
NFKC_CHARS_TO_NORMALIZE.set(p2, replacement);
224-
}
220+
const replacement = NFKC_CHARS_TO_NORMALIZE.getOrInsertComputed(
221+
p2,
222+
() => p2.normalize("NFKC")
223+
);
225224
const jj = replacement.length;
226225
for (let j = 1; j < jj; j++) {
227226
positions.push(i - shift + j, shift - j);

0 commit comments

Comments
 (0)