From 0c9ab84846f68982888a6b2af2ed75f4fd140ea2 Mon Sep 17 00:00:00 2001 From: Raymond Hill Date: Sun, 4 Sep 2022 10:40:26 -0400 Subject: [PATCH] Fix redundant calls to extract image data Related issue: - https://github.com/uBlockOrigin/uBlock-issues/issues/2243#issuecomment-1236194011 --- platform/common/vapi-background.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/platform/common/vapi-background.js b/platform/common/vapi-background.js index 08f7d4d43..996df0c5a 100644 --- a/platform/common/vapi-background.js +++ b/platform/common/vapi-background.js @@ -703,7 +703,7 @@ vAPI.setIcon = (( ) => { const path = icons[i].path; for ( const key in path ) { if ( path.hasOwnProperty(key) === false ) { continue; } - imgs.push({ i: i, p: key }); + imgs.push({ i: i, p: key, cached: false }); } } @@ -724,6 +724,7 @@ vAPI.setIcon = (( ) => { const ctx = document.createElement('canvas').getContext('2d'); const iconData = [ null, null ]; for ( const img of imgs ) { + if ( img.cached ) { continue; } const w = img.r.naturalWidth, h = img.r.naturalHeight; ctx.width = w; ctx.height = h; ctx.clearRect(0, 0, w, h); @@ -741,6 +742,7 @@ vAPI.setIcon = (( ) => { return; } iconData[img.i][img.p] = imgData; + img.cached = true; } for ( let i = 0; i < iconData.length; i++ ) { if ( iconData[i] ) {