From 2e48239056462ba4ce1da96da4b363c916875b5b Mon Sep 17 00:00:00 2001 From: Ian Gilman Date: Wed, 19 Jun 2013 09:58:22 -0700 Subject: [PATCH] Addressing code review comments --- src/openseadragon.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/openseadragon.js b/src/openseadragon.js index 5531831b..69434754 100644 --- a/src/openseadragon.js +++ b/src/openseadragon.js @@ -1686,12 +1686,15 @@ window.OpenSeadragon = window.OpenSeadragon || function( options ){ if ( !iIntervalId ) { iIntervalId = setInterval( function() { if ( aAnimQueue.length ) { + var time = (new Date()).getTime(); // Process all of the currently outstanding frame // requests, but none that get added during the // processing. - var time = +new Date(); + // Swap the arrays so we don't have to create a new + // array every frame. + var temp = processing; processing = aAnimQueue; - aAnimQueue = []; + aAnimQueue = temp; while ( processing.length ) { processing.shift()[ 1 ]( time ); } @@ -1718,7 +1721,8 @@ window.OpenSeadragon = window.OpenSeadragon || function( options ){ } // If it's not in the queue, it may be in the set we're currently - // processing. + // processing (if cancelAnimationFrame is called from within a + // requestAnimationFrame callback). for ( i = 0, j = processing.length; i < j; i += 1 ) { if ( processing[ i ][ 0 ] === requestId ) { processing.splice( i, 1 );