W3C home > Mailing lists > Public > www-validator-cvs@w3.org > March 2008

2002/css-validator/org/w3c/css/parser CssSelectors.java,1.22,1.23

From: Yves Lafon via cvs-syncmail <cvsmail@w3.org>
Date: Thu, 20 Mar 2008 14:51:48 +0000
To: www-validator-cvs@w3.org
Message-Id: <E1JcM7Q-0006xX-VH@lionel-hutz.w3.org>

Update of /sources/public/2002/css-validator/org/w3c/css/parser
In directory hutz:/tmp/cvs-serv26712

Modified Files:
	CssSelectors.java 
Log Message:
added support to freeze the structure and generate more optimizations (no more list traversal for consistency checks)


Index: CssSelectors.java
===================================================================
RCS file: /sources/public/2002/css-validator/org/w3c/css/parser/CssSelectors.java,v
retrieving revision 1.22
retrieving revision 1.23
diff -u -d -r1.22 -r1.23
--- CssSelectors.java	20 Mar 2008 12:15:05 -0000	1.22
+++ CssSelectors.java	20 Mar 2008 14:51:46 -0000	1.23
@@ -82,6 +82,7 @@
     private boolean Init;
 
     private String cachedRepresentation = null;
+    private boolean isFinal = false;
 
     /**
      * Create a new CssSelectors with no previous selector.
@@ -369,12 +370,40 @@
 	if (cachedRepresentation == null) {
 	    return false;
 	}
+	if (isFinal) {
+	    return true;
+	}
 	if (next != null) {
 	    return super.isToStringCached() && next.isToStringCached();
 	}
 	return super.isToStringCached();
     }
 
+    /*
+      we are doing this in two steps, as it is possible to have some
+       calls to toString() and do modifications, then at some point
+       everything is frozen (like when StyleSheet.findConflict is called)
+       marking as final (ie: no more modifications) triggers more 
+       optimizations. Things could be better optimized if we were sure
+       that no calls to toString were done before everything is frozen
+    */
+      
+    /*
+     * Mark as final, ie: no more modification to the structure.
+     */
+    public void markAsFinal() {
+	// if something has been changed, reset to force recomputing
+	if (!isFinal) {
+	    if (!isToStringCached()) {
+		cachedRepresentation = null;
+		if (next != null) {
+		    next.markAsFinal();
+		}
+	    }
+	    isFinal = true;
+	}
+    }
+
     /**
      * Get a hashCode.
      */
Received on Thursday, 20 March 2008 14:52:24 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Thursday, 26 April 2012 12:55:00 GMT