Skip to content

Commit

Permalink
Fix redundant calls to extract image data
Browse files Browse the repository at this point in the history
  • Loading branch information
gorhill committed Sep 4, 2022
1 parent e3a0634 commit 0c9ab84
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion platform/common/vapi-background.js
Expand Up @@ -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 });
}
}

Expand All @@ -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);
Expand All @@ -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] ) {
Expand Down

0 comments on commit 0c9ab84

Please sign in to comment.