From bfe265ad31faf9e2a7df5071fe96cb0b775aa1b2 Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Sun, 22 Feb 2026 15:10:02 +0100 Subject: [PATCH 1/3] Use `Map.prototype.getOrInsertComputed()` in the `editorStats` getter --- src/display/annotation_storage.js | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/src/display/annotation_storage.js b/src/display/annotation_storage.js index d09b56218d22a..2403fecf70bc8 100644 --- a/src/display/annotation_storage.js +++ b/src/display/annotation_storage.js @@ -260,13 +260,8 @@ class AnnotationStorage { if (key === "type") { continue; } - let counters = map.get(key); - if (!counters) { - counters = new Map(); - map.set(key, counters); - } - const count = counters.get(val) ?? 0; - counters.set(val, count + 1); + const counters = map.getOrInsertComputed(key, () => new Map()); + counters.set(val, (counters.get(val) ?? 0) + 1); } } if (numberOfDeletedComments > 0 || numberOfEditedComments > 0) { From ab8e67ecff97ed70d2d2041f2f8b0f41180df0d1 Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Sun, 22 Feb 2026 17:54:17 +0100 Subject: [PATCH 2/3] Use `Map.prototype.getOrInsert()` in the `src/display/annotation_layer.js` file --- src/display/annotation_layer.js | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/display/annotation_layer.js b/src/display/annotation_layer.js index e486221c10a36..dc8be6e8de42a 100644 --- a/src/display/annotation_layer.js +++ b/src/display/annotation_layer.js @@ -3877,12 +3877,7 @@ class AnnotationLayer { this.#elements.push(element); if (data.popupRef) { - const elements = popupToElements.get(data.popupRef); - if (!elements) { - popupToElements.set(data.popupRef, [element]); - } else { - elements.push(element); - } + popupToElements.getOrInsert(data.popupRef, []).push(element); } } From c81904ac0a1bcb1597563f041a60d40d358d5090 Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Sun, 22 Feb 2026 17:55:51 +0100 Subject: [PATCH 3/3] Use `Map.prototype.getOrInsertComputed()` in the `src/display/canvas.js` file --- src/display/canvas.js | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/display/canvas.js b/src/display/canvas.js index 3b18f8098810f..94d5c496b925d 100644 --- a/src/display/canvas.js +++ b/src/display/canvas.js @@ -989,11 +989,10 @@ class CanvasGraphics { : [currentTransform.slice(0, 4), fillColor] ); - cache = this._cachedBitmapsMap.get(mainKey); - if (!cache) { - cache = new Map(); - this._cachedBitmapsMap.set(mainKey, cache); - } + cache = this._cachedBitmapsMap.getOrInsertComputed( + mainKey, + () => new Map() + ); const cachedImage = cache.get(cacheKey); if (cachedImage && !isPatternFill) { const offsetX = Math.round(