mirror of
https://github.com/gorhill/uBlock.git
synced 2024-10-04 16:47:15 +02:00
Fix redundant calls to extract image data
Related issue: - https://github.com/uBlockOrigin/uBlock-issues/issues/2243#issuecomment-1236194011
This commit is contained in:
parent
e3a0634945
commit
0c9ab84846
@ -703,7 +703,7 @@ vAPI.setIcon = (( ) => {
|
|||||||
const path = icons[i].path;
|
const path = icons[i].path;
|
||||||
for ( const key in path ) {
|
for ( const key in path ) {
|
||||||
if ( path.hasOwnProperty(key) === false ) { continue; }
|
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 ctx = document.createElement('canvas').getContext('2d');
|
||||||
const iconData = [ null, null ];
|
const iconData = [ null, null ];
|
||||||
for ( const img of imgs ) {
|
for ( const img of imgs ) {
|
||||||
|
if ( img.cached ) { continue; }
|
||||||
const w = img.r.naturalWidth, h = img.r.naturalHeight;
|
const w = img.r.naturalWidth, h = img.r.naturalHeight;
|
||||||
ctx.width = w; ctx.height = h;
|
ctx.width = w; ctx.height = h;
|
||||||
ctx.clearRect(0, 0, w, h);
|
ctx.clearRect(0, 0, w, h);
|
||||||
@ -741,6 +742,7 @@ vAPI.setIcon = (( ) => {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
iconData[img.i][img.p] = imgData;
|
iconData[img.i][img.p] = imgData;
|
||||||
|
img.cached = true;
|
||||||
}
|
}
|
||||||
for ( let i = 0; i < iconData.length; i++ ) {
|
for ( let i = 0; i < iconData.length; i++ ) {
|
||||||
if ( iconData[i] ) {
|
if ( iconData[i] ) {
|
||||||
|
Loading…
Reference in New Issue
Block a user