Skip to content

Commit 7b451f6

Browse files
Merge pull request #20716 from Snuffleupagus/src-display-getOrInsert
Use `Map.prototype.getOrInsert()` more in the `src/display/` folder
2 parents 5bb35ee + c81904a commit 7b451f6

2 files changed

Lines changed: 5 additions & 11 deletions

File tree

src/display/annotation_layer.js

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3877,12 +3877,7 @@ class AnnotationLayer {
38773877
this.#elements.push(element);
38783878

38793879
if (data.popupRef) {
3880-
const elements = popupToElements.get(data.popupRef);
3881-
if (!elements) {
3882-
popupToElements.set(data.popupRef, [element]);
3883-
} else {
3884-
elements.push(element);
3885-
}
3880+
popupToElements.getOrInsert(data.popupRef, []).push(element);
38863881
}
38873882
}
38883883

src/display/canvas.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -989,11 +989,10 @@ class CanvasGraphics {
989989
: [currentTransform.slice(0, 4), fillColor]
990990
);
991991

992-
cache = this._cachedBitmapsMap.get(mainKey);
993-
if (!cache) {
994-
cache = new Map();
995-
this._cachedBitmapsMap.set(mainKey, cache);
996-
}
992+
cache = this._cachedBitmapsMap.getOrInsertComputed(
993+
mainKey,
994+
() => new Map()
995+
);
997996
const cachedImage = cache.get(cacheKey);
998997
if (cachedImage && !isPatternFill) {
999998
const offsetX = Math.round(

0 commit comments

Comments
 (0)