Fix redundant calls to extract image data

Related issue:
- https://github.com/uBlockOrigin/uBlock-issues/issues/2243#issuecomment-1236194011
This commit is contained in:
Raymond Hill 2022-09-04 10:40:26 -04:00
parent e3a0634945
commit 0c9ab84846
No known key found for this signature in database
GPG Key ID: 25E1490B761470C2
1 changed files with 3 additions and 1 deletions

View File

@ -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] ) {