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

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

From: Yves Lafon via cvs-syncmail <cvsmail@w3.org>
Date: Thu, 20 Mar 2008 12:15:07 +0000
To: www-validator-cvs@w3.org
Message-Id: <E1JcJfn-0004YS-RO@lionel-hutz.w3.org>

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

Modified Files:
	CssSelectors.java 
Log Message:
optimizations in toString generation (along with org.w3c.css.selectors.SelectorsList)


Index: CssSelectors.java
===================================================================
RCS file: /sources/public/2002/css-validator/org/w3c/css/parser/CssSelectors.java,v
retrieving revision 1.21
retrieving revision 1.22
diff -u -d -r1.21 -r1.22
--- CssSelectors.java	13 Sep 2007 10:04:54 -0000	1.21
+++ CssSelectors.java	20 Mar 2008 12:15:05 -0000	1.22
@@ -81,6 +81,8 @@
     // see isEmpty and addProperty
     private boolean Init;
 
+    private String cachedRepresentation = null;
+
     /**
      * Create a new CssSelectors with no previous selector.
      */
@@ -155,14 +157,14 @@
      *
      * @return the value of the attribute
      */
-    public AtRule getAtRule() {
+    public final AtRule getAtRule() {
 	return atRule;
     }
 
     /**
      * Get the element.
      */
-    public String getElement() {
+    public final String getElement() {
 	return element;
     }
 
@@ -170,7 +172,7 @@
      * Returns <code>true</code> if the element is a block level element (HTML
      * only)
      */
-    public boolean isBlockLevelElement() {
+    public final boolean isBlockLevelElement() {
 	return isBlock;
     }
 
@@ -311,7 +313,8 @@
 
     public void addAttribute(AttributeSelector attribute)
     throws InvalidParamException {
-	for(int i = 0; i < size(); i++) {
+	int _s = size();
+	for(int i = 0; i < _s; i++) {
 	    Selector s = (Selector) getSelector(i);
 	    // add warnings if some selectors are incompatible
 	    // e.g. [lang=en][lang=fr]
@@ -350,12 +353,26 @@
      */
     public String toString() {
 	// I'm in reverse order, so compute the next before the current
-	StringBuffer sbrep = new StringBuffer();
+	if (isToStringCached()) {
+	    return cachedRepresentation;
+	}
+	StringBuilder sbrep = new StringBuilder();
 	if (next != null) {
 	    sbrep.append(next.toString());
 	}
 	sbrep.append(super.toString());
-	return sbrep.toString();
+	cachedRepresentation = sbrep.toString();
+	return cachedRepresentation;
+    }
+
+    public boolean isToStringCached() {
+	if (cachedRepresentation == null) {
+	    return false;
+	}
+	if (next != null) {
+	    return super.isToStringCached() && next.isToStringCached();
+	}
+	return super.isToStringCached();
     }
 
     /**
@@ -456,15 +473,15 @@
 	}
     }
 
-    final boolean canApply(ArrayList attrs, ArrayList attrs2) {
+    final boolean canApply(ArrayList<Selector> attrs, ArrayList<Selector> attrs2) {
 	if(attrs.size() > 0) {
 	    for(int i = 0; i < attrs.size(); i++) {
-		Selector selector = (Selector) attrs.get(i);
+		Selector selector = attrs.get(i);
 
 		Selector other = null;
 		int j = 0;
 		for(; j < attrs2.size(); j++) {
-		    other = (Selector) attrs2.get(j);
+		    other = attrs2.get(j);
 		    if(!other.equals(selector)) {
 			other = null;
 		    }
Received on Thursday, 20 March 2008 12:15:43 GMT

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