Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: lib/icon.js

Issue 29334778: Issue 3532 - Improved preformance of icon animation and fixed a memory leak (Closed)
Patch Set: Created Jan. 27, 2016, 6:57 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/icon.js
===================================================================
--- a/lib/icon.js
+++ b/lib/icon.js
@@ -27,6 +27,7 @@
let frameInterval = null;
let animationInterval = null;
+let onActivated = null;
let whitelistedState = new ext.PageMap();
function loadImage(url)
@@ -119,30 +120,36 @@
{
function playAnimation(frames)
Sebastian Noack 2016/01/27 19:09:20 If you don't mind, I'd also like to move that func
kzar 2016/01/28 09:51:04 Sure I don't mind if you'd like to do that. (The f
Sebastian Noack 2016/01/28 10:14:21 Done.
{
- let animationStep = 0;
Sebastian Noack 2016/01/27 19:09:20 Unrelated: We always define variables where we nee
kzar 2016/01/28 09:51:03 Acknowledged.
ext.pages.query({active: true}, pages =>
{
- function appendActivePage(page)
- {
+ let animationStep = 0;
+ let opacity = 0;
+
+ onActivated = page => {
kzar 2016/01/28 09:51:04 Arrow functions are for anonymous functions, if i
Sebastian Noack 2016/01/28 10:14:21 We have to assign to the global variable onActivat
kzar 2016/01/28 10:19:57 Acknowledged.
pages.push(page);
- }
- ext.pages.onActivated.addListener(appendActivePage);
+ setIcon(page, notificationType, opacity, frames);
+ };
+ ext.pages.onActivated.addListener(onActivated);
frameInterval = setInterval(() =>
{
- let opacity = frameOpacities[animationStep++];
- for (let page of pages)
+ let oldOpacity = opacity;
+ opacity = frameOpacities[animationStep++];
+
+ if (opacity != oldOpacity)
Sebastian Noack 2016/01/27 19:09:20 On my notebook (X230 with i7), I observed signific
kzar 2016/01/28 09:51:04 Of course, good idea.
{
- if (whitelistedState.has(page))
- setIcon(page, notificationType, opacity, frames);
- };
Sebastian Noack 2016/01/27 19:09:20 Unrelated: Removed redundant semicolon.
kzar 2016/01/28 09:51:04 Acknowledged.
+ for (let page of pages)
+ {
+ if (whitelistedState.has(page))
+ setIcon(page, notificationType, opacity, frames);
+ }
+ }
if (animationStep > numberOfFrames)
{
- animationStep = 0;
Sebastian Noack 2016/01/27 19:09:20 Unrelated: Resetting that value is unneeded, as th
kzar 2016/01/28 09:51:04 Acknowledged.
clearInterval(frameInterval);
- frameInterval = null;
- ext.pages.onActivated.removeListener(appendActivePage);
+ ext.pages.onActivated.removeListener(onActivated);
+ frameInterval = onActivated = null;
}
}, 100);
});
@@ -179,7 +186,9 @@
clearInterval(frameInterval);
if (animationInterval != null)
clearInterval(animationInterval);
- frameInterval = animationInterval = null;
+ if (onActivated)
Sebastian Noack 2016/01/27 19:09:20 Yeah, that was the memory leak mentioned in the is
kzar 2016/01/28 09:51:04 Dang, good point. (Note, my stopAnimation closure
Sebastian Noack 2016/01/28 10:14:21 (Not really, it doesn't matter where you do the cl
+ ext.pages.onActivated.removeListener(onActivated);
+ frameInterval = animationInterval = onActivated = null;
};
/**
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld