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); } } 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) { 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(