Revision: 1880
          http://svn.sourceforge.net/vexi/?rev=1880&view=rev
Author:   clrg
Date:     2007-06-26 16:46:41 -0700 (Tue, 26 Jun 2007)

Log Message:
-----------
Optimize all loops previously indirectly over using indexNode
- anything referring to nextSibling/prevSibling
- anything referring to firstVisibleChild/nextVisibleChild
- replace the above using efficient getChild(int) calls instead

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

Modified: core/trunk/org.vexi.core/src/org/vexi/core/Box.jpp
===================================================================
--- core/trunk/org.vexi.core/src/org/vexi/core/Box.jpp  2007-06-26 23:26:52 UTC 
(rev 1879)
+++ core/trunk/org.vexi.core/src/org/vexi/core/Box.jpp  2007-06-26 23:46:41 UTC 
(rev 1880)
@@ -103,8 +103,6 @@
 
     // Trivial Helper Methods (should be inlined) 
/////////////////////////////////////////
 
-    private final Box firstVisibleChild() { Box b = getChild(0); return b == 
null || (b.test(DISPLAY)) ? b : b.nextVisibleSibling(); }
-    private final Box nextVisibleSibling() { Box b = nextSibling(); return b 
== null || (b.test(DISPLAY)) ? b : b.nextVisibleSibling(); }
     private final Box getRoot() { return parent == null ? this : 
parent.getRoot(); }
     protected final Surface getSurface() { return Surface.fromBox(getRoot()); }
 
@@ -383,8 +381,11 @@
 
         // reconstrain any children
         if (test(CONSTRAIN_DESCENDENT)) {
-            for (Box c = firstVisibleChild(); c != null; c = 
c.nextVisibleSibling())
+            int i = 0;
+            for (Box c = getChild(0); c != null; c = getChild(++i)) {
+                if (!c.test(DISPLAY)) continue;
                 c.constrain();
+            }
             clear(CONSTRAIN_DESCENDENT);
         }
 
@@ -403,14 +404,20 @@
             // accumulate child contentwidth
             if (test(ORIENT) == HORIZONTAL) {
                 contentwidth = 0;
-                for(Box c = firstVisibleChild(); c != null; c = 
c.nextVisibleSibling())
+                int i = 0;
+                for (Box c = getChild(0); c != null; c = getChild(++i)) {
+                    if (!c.test(DISPLAY)) continue;
                     contentwidth += c.contentwidth;
+                }
 
             // maximum child contentwidth
             } else {
                 contentwidth = 0;
-                for(Box c = firstVisibleChild(); c != null; c = 
c.nextVisibleSibling())
+                int i = 0;
+                for (Box c = getChild(0); c != null; c = getChild(++i)) {
+                    if (!c.test(DISPLAY)) continue;
                     contentwidth = max(contentwidth, c.contentwidth);
+                }
             }
             //#end
         }
@@ -444,7 +451,9 @@
             
             // absolute layout
             if (test(ABSOLUTE)) {
-                for(Box child = firstVisibleChild(); child != null; child = 
child.nextVisibleSibling()) {
+                int i = 0;
+                for (Box child = getChild(0); child != null; child = 
getChild(++i)) {
+                    if (!child.test(DISPLAY)) continue;
                     child_width = child.test(HSHRINK) ? child.contentwidth : 
max(child.contentwidth, min(child.maxwidth, width - child.x));
                     child_height = child.test(VSHRINK) ? child.contentheight : 
max(child.contentheight, min(child.maxheight, height - child.y));
                     child.tryResize(child_width, child_height);
@@ -458,7 +467,9 @@
                 if (test(ORIENT) == HORIZONTAL) {
                     // simple case - no slack, place children next to eachother
                     if (!test(HAS_WIDTH_SLACK) && 0 >= width - contentwidth) {
-                        for(Box child = firstVisibleChild(); child != null; 
child = child.nextVisibleSibling()) {
+                        int i = 0;
+                        for (Box child = getChild(0); child != null; child = 
getChild(++i)) {
+                            if (!child.test(DISPLAY)) continue;
                             // height, y
                             child_height = child.test(VSHRINK) ? 
child.contentheight : min(child.maxheight, height);
                             child_y = child.test(ALIGN_TOP) ? 0 : 
(child.test(ALIGN_BOTTOM) ?
@@ -473,7 +484,9 @@
                     } else {
                         // first establish how many children will accept slack
                         int count = 0, consumed = 0;
-                        for(Box child = firstVisibleChild(); child != null; 
child = child.nextVisibleSibling()) {
+                        int i = 0;
+                        for (Box child = getChild(0); child != null; child = 
getChild(++i)) {
+                            if (!child.test(DISPLAY)) continue;
                             if (!child.test(HSHRINK)) count++;
                             consumed += child.contentwidth;
                         }
@@ -485,7 +498,9 @@
                         int shift, space;
 
                         // now we know how we are assigning slack, second pass 
handles layout
-                        for(Box child = firstVisibleChild(); child != null; 
child = child.nextVisibleSibling()) {
+                        i = 0;
+                        for (Box child = getChild(0); child != null; child = 
getChild(++i)) {
+                            if (!child.test(DISPLAY)) continue;
                             // height, y
                             child_height = child.test(VSHRINK) ? 
child.contentheight : min(child.maxheight, height);
                             child_y = child.test(ALIGN_TOP) ? 0 : 
(child.test(ALIGN_BOTTOM) ?
@@ -527,7 +542,9 @@
                 } else {
                     // simple case - no slack
                     if (!test(HAS_HEIGHT_SLACK) && 0 >= height - 
contentheight) {
-                        for(Box child = firstVisibleChild(); child != null; 
child = child.nextVisibleSibling()) {
+                        int i = 0;
+                        for (Box child = getChild(0); child != null; child = 
getChild(++i)) {
+                            if (!child.test(DISPLAY)) continue;
                             // width, x
                             child_width = child.test(HSHRINK) ? 
child.contentwidth : min(child.maxwidth, width);
                             child_x = child.test(ALIGN_LEFT) ? 0 : 
(child.test(ALIGN_RIGHT) ?
@@ -540,7 +557,9 @@
                     // take into account slack - slightly more processing
                     } else {
                         int count = 0, consumed = 0;
-                        for(Box child = firstVisibleChild(); child != null; 
child = child.nextVisibleSibling()) {
+                        int i = 0;
+                        for (Box child = getChild(0); child != null; child = 
getChild(++i)) {
+                            if (!child.test(DISPLAY)) continue;
                             if (!child.test(VSHRINK)) count++;
                             consumed += child.contentheight;
                         }
@@ -549,7 +568,9 @@
                         float total = (float)0.01;
                         int shift, space;
 
-                        for(Box child = firstVisibleChild(); child != null; 
child = child.nextVisibleSibling()) {
+                        i = 0;
+                        for (Box child = getChild(0); child != null; child = 
getChild(++i)) {
+                            if (!child.test(DISPLAY)) continue;
                             // width, x
                             child_width = child.test(HSHRINK) ? 
child.contentwidth : min(child.maxwidth, width);
                             child_x = child.test(ALIGN_LEFT) ? 0 : 
(child.test(ALIGN_RIGHT) ?
@@ -584,8 +605,11 @@
 
         if (test(PLACE_DESCENDENT)) {
             clear(PLACE_DESCENDENT);
-            for (Box child = firstVisibleChild(); child != null; child = 
child.nextVisibleSibling())
+            int i = 0;
+            for (Box child = getChild(0); child != null; child = 
getChild(++i)) {
+                if (!child.test(DISPLAY)) continue;
                 child.place();
+            }
         }
     }
 
@@ -635,20 +659,26 @@
         
         // absolute layout means we must attempt to render all visible children
         if (test(ABSOLUTE)) {
-            for (Box b = firstVisibleChild(); b != null; b = 
b.nextVisibleSibling()) {
+            int i = 0;
+            for (Box b = getChild(0); b != null; b = getChild(++i)) {
+                if (!b.test(DISPLAY)) continue;
                 b.render(globalx, globaly, cx1, cy1, cx2, cy2, buf);
             }
 
         // packed layout allows us to know early when to stop processing
         } else {
             if (test(ORIENT) == HORIZONTAL) {
-                for (Box b = firstVisibleChild(); b != null; b = 
b.nextVisibleSibling()) {
+                int i = 0;
+                for (Box b = getChild(0); b != null; b = getChild(++i)) {
+                    if (!b.test(DISPLAY)) continue;
                     if (globalx + b.x > cx2) break;
                     if (globalx + b.x + b.width < cx1) continue;
                     b.render(globalx, globaly, cx1, cy1, cx2, cy2, buf);
                 }
             } else {
-                for (Box b = firstVisibleChild(); b != null; b = 
b.nextVisibleSibling()) {
+                int i = 0;
+                for (Box b = getChild(0); b != null; b = getChild(++i)) {
+                    if (!b.test(DISPLAY)) continue;
                     if (globaly + b.y > cy2) break;
                     if (globaly + b.y + b.height < cy1) continue;
                     b.render(globalx, globaly, cx1, cy1, cx2, cy2, buf);
@@ -766,7 +796,8 @@
     /** fire traps on visible for this box and it's children */
     private void fireVisibleTraps(boolean visibility, JS value) throws JSExn {
         boolean b = prePutTriggerTrapsAndCatchExceptions(SC_visible, value);
-        for (Box child = getChild(0); child != null; child = 
child.nextSibling())
+        int i = 0;
+        for (Box child = getChild(0); child != null; child = getChild(++i))
             if (child.test(DISPLAY) != visibility) 
child.fireVisibleTraps(visibility, value);
         postPutTriggerTrapsAndCatchExceptions(SC_visible, b);
     }
@@ -1386,8 +1417,6 @@
     private final void insertNode(int p, Box b) { if (bt == null) bt = new 
BasicTree(); bt.insertNode(p,b); }
 
     // self
-    private final Box nextSibling() { return parent == null ? null : 
parent.getChild(parent.indexNode(this) + 1); }
-    private final Box prevSibling() { return parent == null ? null : 
parent.getChild(parent.indexNode(this) - 1); }
     private final int getIndexInParent() { return parent == null ? 0 : 
parent.indexNode(this); }
 
 


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 DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Vexi-svn mailing list
Vexi-svn@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/vexi-svn

Reply via email to