[Laszlo-checkins] r11092 - in openlaszlo/trunk/WEB-INF/lps/lfc: kernel/swf9 services
bargull@openlaszlo.org
bargull at openlaszlo.org
Thu Sep 18 23:59:14 PDT 2008
Author: bargull
Date: 2008-09-18 23:59:10 -0700 (Thu, 18 Sep 2008)
New Revision: 11092
Modified:
openlaszlo/trunk/WEB-INF/lps/lfc/kernel/swf9/LzTimeKernel.as
openlaszlo/trunk/WEB-INF/lps/lfc/services/LzTimer.lzs
Log:
Change 20080918-bargull-C3r by bargull at dell--p4--2-53 on 2008-09-18 15:24:48
in /home/Admin/src/svn/openlaszlo/trunk
for http://svn.openlaszlo.org/openlaszlo/trunk
Summary: avoid function closure in lz.Timer
New Features:
Bugs Fixed: LPP-7005
Technical Reviewer: ptw
QA Reviewer: max
Doc Reviewer: (pending)
Documentation:
Release Notes:
Details:
so we don't need to create a new function closure for every new timer.
Tests:
attached at bugreport, tested in swf8-9, dhtml (IE, FF, Opera)
Modified: openlaszlo/trunk/WEB-INF/lps/lfc/kernel/swf9/LzTimeKernel.as
===================================================================
--- openlaszlo/trunk/WEB-INF/lps/lfc/kernel/swf9/LzTimeKernel.as 2008-09-19 06:51:40 UTC (rev 11091)
+++ openlaszlo/trunk/WEB-INF/lps/lfc/kernel/swf9/LzTimeKernel.as 2008-09-19 06:59:10 UTC (rev 11092)
@@ -9,16 +9,22 @@
*/
// Receives and sends timing events
-dynamic class LzTimeKernelClass {
- #passthrough (toplevel:true) {
- import flash.utils.*;
+final class LzTimeKernelClass {
+ #passthrough (toplevel:true) {
+ import flash.utils.getTimer;
+ import flash.utils.setTimeout;
+ import flash.utils.setInterval;
+ import flash.utils.clearTimeout;
+ import flash.utils.clearInterval;
}#
- function LzTimeKernelClass(){
- this.getTimer = getTimer;
- this.setTimeout = setTimeout;
- this.setInterval = setInterval;
- this.clearTimeout = clearTimeout;
- this.clearInterval = clearInterval;
+
+ const getTimer :Function = flash.utils.getTimer;
+ const setTimeout :Function = flash.utils.setTimeout;
+ const setInterval :Function = flash.utils.setInterval;
+ const clearTimeout :Function = flash.utils.clearTimeout;
+ const clearInterval :Function = flash.utils.clearInterval;
+
+ function LzTimeKernelClass() {
}
}
var LzTimeKernel = new LzTimeKernelClass();
Modified: openlaszlo/trunk/WEB-INF/lps/lfc/services/LzTimer.lzs
===================================================================
--- openlaszlo/trunk/WEB-INF/lps/lfc/services/LzTimer.lzs 2008-09-19 06:51:40 UTC (rev 11091)
+++ openlaszlo/trunk/WEB-INF/lps/lfc/services/LzTimer.lzs 2008-09-19 06:59:10 UTC (rev 11092)
@@ -67,9 +67,9 @@
* increased code complexity.
*
*/
-class LzTimerService {
+public final class LzTimerService {
/** @access private */
- var timerList = new Object;
+ var timerList :Object = new Object;
/**
* The timer service. Also available as the global
@@ -94,6 +94,52 @@
LzTimerService.LzTimer = new LzTimerService();
/**
+ * Executes the delegate 'p.delegate' and calls 'removeTimerWithID' to
+ * remove the timer from the timerlist.
+ *
+ * @param Object p: contains the delegate to be called and the timer-id
+ * @access private
+ */
+ var execDelegate:Function = function (p:Object) :void {
+ // Use lz.Timer explicitly below; "this" is not lz.Timer here.
+ var del:LzDelegate = p.delegate;
+ lz.Timer.removeTimerWithID(del, p.id);
+ // Inlining LzDelegate.execute()
+ if (del.enabled && del.c) {
+ del.execute( (new Date()).getTime() );
+ // TODO: inlining causes problems with DHTML, see LPP-5917
+ //if (! del.c.__LZdeleted && del.c[del.f]) del.c[del.f]( (new Date()).getTime() );
+ }
+ }
+
+ /**
+ * Removes the timer with the given id that calls the given delegate from the
+ * timerlist.
+ *
+ * @param LzDelegate d: The delegate called by the timer to be removed.
+ * @param id: the id of the timer to remove.
+ * @access private
+ */
+ function removeTimerWithID (d:LzDelegate, id:uint) :void {
+ var delID:int = d.__delegateID;
+ var tle:* = this.timerList[delID];
+ if (tle != null) {
+ if (tle instanceof Array) {
+ for (var i:int = 0; i < tle.length; i++) {
+ if (tle[i] == id) {
+ tle.splice(i, 1);
+ if (tle.length == 0)
+ delete this.timerList[delID];
+ break;
+ }
+ }
+ } else if (tle == id) {
+ delete this.timerList[delID];
+ }
+ }
+ }
+
+ /**
* Adds a timer. Note: The timer guarantees that the delegate will
* not be called before the number of milliseconds specified here,
* but cannot guarantee that it will be called at exactly that time.
@@ -102,42 +148,34 @@
* @param Number millisecs: The number of millisecondss to wait
* before calling the delegate.
*/
- function addTimer ( d , millisecs ){
- var p = { 'delegate' : d };
- var f = function () {
- // This closure captures 'p', and relies on the fact that p.id will
- // have been set by the time the closure is invoked.
-
- // User lz.Timer explicitly below; "this" is not the outer function's
- // this here.
- lz.Timer.removeTimerWithID(p.delegate, p.id);
- var del = p.delegate;
- // Inlining LzDelegate.execute()
- if (del.enabled && del.c) {
- p.delegate.execute( (new Date()).getTime() );
- // TODO: inlining causes problems with DHTML
- //if (! del.c.__LZdeleted && del.c[del.f]) del.c[del.f]( (new Date()).getTime() );
- }
- }
+ function addTimer (d:LzDelegate, millisecs:Number) :uint {
// prevent bogus timeouts which cause exceptions in swf9
if (! millisecs || millisecs < 1) millisecs = 1;
- var id = LzTimeKernel.setTimeout(f, millisecs);
+
+ // This object relies on the fact that p.id will
+ // have been set by the time 'execDelegate' is invoked.
+ var p:Object = {delegate: d};
+ var id:uint = LzTimeKernel.setTimeout(this.execDelegate, millisecs, p);
+ p.id = id;
+
if ($debug) {
// Debug.format("created timer %w for delegate %w\n", id, d);
- if (id instanceof Array)
+ if (id instanceof Array) {
// we rely on the setTimeout value being a non-array, otherwise
// our storage scheme won't work. Error if this happens -- should only
// occur when bootstrapping a new runtime.
Debug.error("setTimeout result type is unexpected; lz.Timer will fail");
+ }
}
- p.id = id;
- var tle = this.timerList[d.__delegateID];
+
+ var delID:int = d.__delegateID;
+ var tle:* = this.timerList[delID];
if (tle == null) {
// single items don't use an array
- this.timerList[d.__delegateID] = id;
+ this.timerList[delID] = id;
} else if (! (tle instanceof Array)) {
// create an array to track ids
- this.timerList[d.__delegateID] = [tle, id];
+ this.timerList[delID] = [tle, id];
} else {
// add onto the array
tle.push(id);
@@ -153,19 +191,20 @@
* removed. If there are multiple timerList entries that call
* delegate d, removes the first in the order received.
*/
- function removeTimer ( d ){
- var tle = this.timerList[d.__delegateID];
- var id = null;
+ function removeTimer (d:LzDelegate) :* {
+ var delID:int = d.__delegateID;
+ var tle:* = this.timerList[delID];
+ var id:* = null;
if (tle != null) {
if (tle instanceof Array) {
id = tle.shift();
LzTimeKernel.clearTimeout(id);
if (tle.length == 0)
- delete this.timerList[d.__delegateID];
+ delete this.timerList[delID];
} else {
id = tle;
LzTimeKernel.clearTimeout(id);
- delete this.timerList[d.__delegateID];
+ delete this.timerList[delID];
}
// Debug.format("cleared timer %w for delegate %w (2)\n", id, d);
}
@@ -173,34 +212,6 @@
}
/**
- * Removes the timer with the given id that calls the given delegate from the
- * timerlist.
- *
- * @param LzDelegate d: The delegate called by the timer to be removed.
- * @param id: the id of the timer to remove.
- * @access private
- */
- function removeTimerWithID ( d, id ){
- var tle = this.timerList[d.__delegateID];
- if (tle != null) {
- if (tle instanceof Array) {
- var i = 0;
- for (i=0; i<tle.length; i++) {
- var id2 = tle[i];
- if (id2 == id) {
- tle.splice(i,1);
- break;
- }
- }
- if (tle.length == 0)
- delete this.timerList[d.__delegateID];
- } else if (tle == id) {
- delete this.timerList[d.__delegateID];
- }
- }
- }
-
- /**
* Resets the timer for the given delegate to the new amount of
* time. If a timer for the delegate is not found, a new timer is
* created.
@@ -213,9 +224,9 @@
* @param millisecs: The number of milliseconds to wait before
* calling the timer.
*/
- function resetTimer ( d , millisecs ){
- this.removeTimer( d );
- return this.addTimer( d , millisecs );
+ function resetTimer (d:LzDelegate, millisecs:Number) :uint {
+ this.removeTimer(d);
+ return this.addTimer(d, millisecs);
}
if ($debug) {
@@ -227,8 +238,8 @@
* @param LzDelegate d: The delegate called by the timer to be
* reset.
*/
- function countTimers ( d ){
- var tle = this.timerList[d.__delegateID];
+ function countTimers (d:LzDelegate) :uint {
+ var tle:* = this.timerList[d.__delegateID];
if (tle == null)
return 0;
else if (tle instanceof Array)
More information about the Laszlo-checkins
mailing list