Author: max
Date: 2007-08-01 16:37:11 -0700 (Wed, 01 Aug 2007)
New Revision: 5901

Modified:
   openlaszlo/branches/wafflecone/WEB-INF/lps/lfc/services/LzCSSStyle.js
Log:
Change 20070801-maxcarlson-k by [EMAIL PROTECTED] on 2007-08-01 12:24:00 PDT
    in /Users/maxcarlson/openlaszlo/wafflecone
    for http://svn.openlaszlo.org/openlaszlo/branches/wafflecone

Summary: Inline LzCSSStyle._selectorApplies() testing and first level of 
recursion

New Features:

Bugs Fixed: LPP-4414 - Improve startup performance (partial)

Technical Reviewer: promanik
QA Reviewer: ben
Doc Reviewer: (pending)

Documentation:

Release Notes:

Details: Do early tests to short-circuit calls to _selectorApplies().  Change 
structure of _selectorApplies() to set a result variable and break rather than 
retunring immediately.  Inline first level of recursion (ugly, but it gets the 
most results).
    

Tests: Silver main.lzx?lzr=dhtml&lzt=html shows a total of 56350 fewer function 
calls in firebug (from 307750 to 251400).  Calls to _selectorApplies() have 
been reduced from 125068 to 66294 calls.



Modified: openlaszlo/branches/wafflecone/WEB-INF/lps/lfc/services/LzCSSStyle.js
===================================================================
--- openlaszlo/branches/wafflecone/WEB-INF/lps/lfc/services/LzCSSStyle.js       
2007-08-01 23:24:46 UTC (rev 5900)
+++ openlaszlo/branches/wafflecone/WEB-INF/lps/lfc/services/LzCSSStyle.js       
2007-08-01 23:37:11 UTC (rev 5901)
@@ -96,7 +96,13 @@
         var r;
         for ( var i = this._rules.length -1; i >=0; i-- ){
             r = this._rules[ i ];
-            if ( this._selectorApplies( r, r.parsed, node ) ){
+            var rp = r.parsed;
+            if ( rp.type == 1 ||
+                 (rp.type == 2 && rp.id == node.id) ||
+                 (rp.type == 3 && (((rp.classname in lz) && (node instanceof 
lz[ rp.classname ])) || ( (rp.classname in global) && (node instanceof global[ 
rp.classname ])))) ||
+                 (rp.type == 5 && node[ rp.attrname ] == rp.attrvalue) ||
+                 (rp.type == 6 && node[ rp.attrname ] == rp.attrvalue && 
(((rp.classname in lz) && (node instanceof lz[ rp.classname ])) || ( 
(rp.classname in global) && (node instanceof global[ rp.classname ])))) ||
+                 this._selectorApplies( r, rp, node ) ){
                 rules.push(r); 
             }
         }
@@ -112,7 +118,13 @@
             //same code as above, but inline to avoid function call overhead
             for ( var i = pprules.length -1; i >=0; i-- ){
                 r = pprules[ i ];
-                if ( this._selectorApplies( r, r.parsed, node ) ){
+                var rp = r.parsed;
+                if ( rp.type == 1 ||
+                 (rp.type == 2 && rp.id == node.id) ||
+                 (rp.type == 3 && (((rp.classname in lz) && (node instanceof 
lz[ rp.classname ])) || ( (rp.classname in global) && (node instanceof global[ 
rp.classname ])))) ||
+                 (rp.type == 5 && node[ rp.attrname ] == rp.attrvalue) ||
+                 (rp.type == 6 && node[ rp.attrname ] == rp.attrvalue && 
(((rp.classname in lz) && (node instanceof lz[ rp.classname ])) || ( 
(rp.classname in global) && (node instanceof global[ rp.classname ])))) ||
+                 this._selectorApplies( r, rp, node ) ){
                     rules.push(r); 
                 }
             }
@@ -249,52 +261,128 @@
   * @access private */
 LzCSSStyle._selectorApplies = function ( rule, rp , node ){
     //rp is the parsed selector
+    var result; 
     switch ( rp.type ){
         case (this._selTypes.star ):
-            return true;
+            result = true;
+            break;
 
         case (this._selTypes.id ):
-            return node.id == rp.id;
+            result = node.id == rp.id;
+            break;
 
+
         case (this._selTypes.tag ):
-            return  ((rp.classname in lz) && (node instanceof lz[ rp.classname 
]))
+            result =  ((rp.classname in lz) && (node instanceof lz[ 
rp.classname ]))
                  || ( (rp.classname in global) && (node instanceof global[ 
rp.classname ]));
+            break;
 
         case (this._selTypes.compound ):
             var curnode = node; 
             var sindex = rp.length -1;
 
-            var lc = rp[ sindex ];
             var firstone = true;
             while ( curnode ){
+                // inline this._selectorApplies here 
+                // this._selectorApplies( rule, rp[ sindex ], curnode )
+                var nrp = rp[sindex]
 
-                if (this._selectorApplies( rule, rp[ sindex ], curnode )){
+                var iresult; 
+                switch ( nrp.type ){
+                    case (this._selTypes.star ):
+                        iresult = true;
+                        break;
+
+                    case (this._selTypes.id ):
+                        iresult = curnode.id == nrp.id;
+                        break;
+
+
+                    case (this._selTypes.tag ):
+                        iresult =  ((nrp.classname in lz) && (curnode 
instanceof lz[ nrp.classname ]))
+                            || ( (nrp.classname in global) && (curnode 
instanceof global[ nrp.classname ]));
+                        break;
+
+                    case (this._selTypes.compound ):
+                        var icurnode = curnode; 
+                        var sindex = nrp.length -1;
+
+                        var ifirstone = true;
+                        while ( icurnode ){
+
+                            var inrp = nrp[sindex]
+                            if ( inrp.type == 1 ||
+                                (inrp.type == 2 && inrp.id == icurnode.id) ||
+                                (inrp.type == 3 && (((inrp.classname in lz) && 
(icurnode instanceof lz[ inrp.classname ])) || ( (inrp.classname in global) && 
(icurnode instanceof global[ inrp.classname ])))) ||
+                                (inrp.type == 5 && icurnode[ inrp.attrname ] 
== inrp.attrvalue) ||
+                                (inrp.type == 6 && icurnode[ inrp.attrname ] 
== inrp.attrvalue && (((inrp.classname in lz) && (icurnode instanceof lz[ 
inrp.classname ])) || ( (inrp.classname in global) && (icurnode instanceof 
global[ inrp.classname ])))) ||
+                                this._selectorApplies( rule, inrp, icurnode )){
+                                if ( sindex-- == 0 ){
+                                    iresult = true;
+                                    break;
+                                }
+                            } else if ( ifirstone ){
+                                //if the last selector doesn't apply, then 
bail -- we'll
+                                //come back for this when we recurse over the 
parents in
+                                //getPropertyValueFor
+                                iresult = false;
+                                break;
+                            }
+
+                            if (icurnode == canvas) break;
+                            icurnode = icurnode.parent;
+                            ifirstone = false;
+                        }
+                        if (iresult == null) iresult = false;
+                        break;
+
+                    case (this._selTypes.attribute ):
+                        iresult = curnode[ nrp.attrname ] == nrp.attrvalue;
+                        break;
+
+                    case (this._selTypes.tagAndAttr ):
+                        if (curnode[ nrp.attrname ] == nrp.attrvalue) {
+                            iresult = ((nrp.classname in lz) && (curnode 
instanceof lz[ nrp.classname ]))
+                                || ( (nrp.classname in global) && (curnode 
instanceof global[ nrp.classname ]));
+                        }
+                        if (iresult == null) iresult = false;
+                        break;
+                }
+                // end inline
+
+                if (iresult){
                     if ( sindex-- == 0 ){
-                        return true;
+                        result = true;
+                        break;
                     }
                 } else if ( firstone ){
                     //if the last selector doesn't apply, then bail -- we'll
                     //come back for this when we recurse over the parents in
                     //getPropertyValueFor
-                    return false;
+                    result = false;
+                    break;
                 }
 
                 if (curnode == canvas) break;
                 curnode = curnode.parent;
                 firstone = false;
             }
-            return false;
+            if (result == null) result = false;
+            break;
 
         case (this._selTypes.attribute ):
-            return node[ rp.attrname ] == rp.attrvalue;
+            result = node[ rp.attrname ] == rp.attrvalue;
+            break;
 
         case (this._selTypes.tagAndAttr ):
             if (node[ rp.attrname ] == rp.attrvalue) {
-                return  ((rp.classname in lz) && (node instanceof lz[ 
rp.classname ]))
+                result = ((rp.classname in lz) && (node instanceof lz[ 
rp.classname ]))
                      || ( (rp.classname in global) && (node instanceof global[ 
rp.classname ]));
             }
-            return false; 
+            if (result == null) result = false;
+            break;
     }
+    return result;
 }
 
 /** @access private */


_______________________________________________
Laszlo-checkins mailing list
[email protected]
http://www.openlaszlo.org/mailman/listinfo/laszlo-checkins

Reply via email to