diff --git a/src/display/canvas.js b/src/display/canvas.js index 3b18f8098..94d5c496b 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(