Revision: 3175
          http://vexi.svn.sourceforge.net/vexi/?rev=3175&view=rev
Author:   clrg
Date:     2008-11-05 23:00:29 +0000 (Wed, 05 Nov 2008)

Log Message:
-----------
Minor optimization of TrapChain - use counter instead of assignment

Modified Paths:
--------------
    trunk/core/org.vexi.core/src/org/vexi/core/Box.jpp

Modified: trunk/core/org.vexi.core/src/org/vexi/core/Box.jpp
===================================================================
--- trunk/core/org.vexi.core/src/org/vexi/core/Box.jpp  2008-11-05 22:54:05 UTC 
(rev 3174)
+++ trunk/core/org.vexi.core/src/org/vexi/core/Box.jpp  2008-11-05 23:00:29 UTC 
(rev 3175)
@@ -1546,61 +1546,73 @@
 
     /** represents a chain of traps that may span multiple boxes */
     public static final class TrapChain {
-        TrapChain next;
+        int chainlength = 0;
         JSExn exn;
-        
-        public TrapChain(TrapChain trapchain) { next = trapchain; }
-        
+
         public JS beforeCascade(Box b, JS prop, JS val) {
             Trap t = b.wtrap(prop);
             try {
-                if (t != null) return Main.SCHEDULER.runBeforePut(t, val);
+                if (t != null) {
+                    chainlength++;
+                    return Main.SCHEDULER.runBeforePut(t, val);
+                }
             } catch (JSExn e) {
                 exn = e;
             }
             return null;
         }
-        
+
         public void finishTraps() throws JSExn { finishTraps(exn); }
+
         private void finishTraps(JSExn exn) throws JSExn {
-            Main.SCHEDULER.runAfterPut(exn);
-            if (next!=null) next.finishTraps();
-            else if (exn!=null) throw exn;
+            while (chainlength>0) {
+                chainlength--;
+                Main.SCHEDULER.runAfterPut(exn);
+            }
+            if (exn != null) throw exn;
         }
     }
 
     /** fires surface traps in a root-first traversal of a box tree */
     private final TrapChain fireSurfaceTraps(JS val, TrapChain trapchain) {
         if (test(SURFACE_TRAP)) {
-            trapchain = new TrapChain(trapchain);
+            if (trapchain == null) trapchain = new TrapChain();
             val = trapchain.beforeCascade(this, SC_surface, val);
-            if (trapchain.exn!=null) return trapchain;
+            // interrupted by a JS exception
+            if (trapchain.exn != null)
+                return trapchain;
         }
-        for (int i=0; i<treeSize(); i++) {
+        for (int i = 0; i < treeSize(); i++) {
             Box b = getChild(i);
             trapchain = b.fireSurfaceTraps(val, trapchain);
-            if (trapchain!=null && trapchain.exn!=null) return trapchain;
+            // interrupted by a JS exception
+            if (trapchain != null && trapchain.exn != null)
+                return trapchain;
         }
         return trapchain;
     }
 
     /** function used by Platform.createSurface to invoke fireVisibleTraps */
     public final TrapChain fireVisibleTraps(boolean visible) {
-        return fireVisibleTraps(visible?JSU.T:JSU.F, null);
+        return fireVisibleTraps(visible ? JSU.T : JSU.F, null);
     }
 
     /** fires visible traps in a root-first traversal of a box tree */
     private final TrapChain fireVisibleTraps(JS val, TrapChain trapchain) {
         if (test(VISIBLE_TRAP)) {
-            trapchain = new TrapChain(trapchain);
+            if (trapchain == null) trapchain = new TrapChain();
             val = trapchain.beforeCascade(this, SC_visible, val);
-            if (trapchain.exn!=null) return trapchain; 
+            // interrupted by a JS exception
+            if (trapchain.exn != null)
+                return trapchain;
         }
-        for (int i=0; i<treeSize(); i++) {
+        for (int i = 0; i < treeSize(); i++) {
             Box b = getChild(i);
             if (b.test(DISPLAY)) {
                 trapchain = b.fireVisibleTraps(val, trapchain);
-                if (trapchain!=null && trapchain.exn!=null) return trapchain;
+                // interrupted by a JS exception
+                if (trapchain != null && trapchain.exn != null)
+                    return trapchain;
             }
         }
         return trapchain;


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.

-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Vexi-svn mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/vexi-svn

Reply via email to