You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xerces.apache.org by mr...@apache.org on 2007/12/23 07:38:18 UTC

svn commit: r606543 - in /xerces/java/trunk/src/org/apache/xerces/impl/dtd: DTDGrammar.java XMLDTDDescription.java

Author: mrglavas
Date: Sat Dec 22 22:38:17 2007
New Revision: 606543

URL: http://svn.apache.org/viewvc?rev=606543&view=rev
Log:
Some minor performance improvements. Replace the 
usage of Vector with the unsynchronized ArrayList.

Modified:
    xerces/java/trunk/src/org/apache/xerces/impl/dtd/DTDGrammar.java
    xerces/java/trunk/src/org/apache/xerces/impl/dtd/XMLDTDDescription.java

Modified: xerces/java/trunk/src/org/apache/xerces/impl/dtd/DTDGrammar.java
URL: http://svn.apache.org/viewvc/xerces/java/trunk/src/org/apache/xerces/impl/dtd/DTDGrammar.java?rev=606543&r1=606542&r2=606543&view=diff
==============================================================================
--- xerces/java/trunk/src/org/apache/xerces/impl/dtd/DTDGrammar.java (original)
+++ xerces/java/trunk/src/org/apache/xerces/impl/dtd/DTDGrammar.java Sat Dec 22 22:38:17 2007
@@ -17,8 +17,8 @@
 
 package org.apache.xerces.impl.dtd;
 
+import java.util.ArrayList;
 import java.util.Hashtable;
-import java.util.Vector;
 
 import org.apache.xerces.impl.dtd.models.CMAny;
 import org.apache.xerces.impl.dtd.models.CMBinOp;
@@ -790,16 +790,17 @@
     public void endDTD(Augmentations augs) throws XNIException {
         fIsImmutable = true;
         // make sure our description contains useful stuff...
-        if(fGrammarDescription.getRootName() == null) {
+        if (fGrammarDescription.getRootName() == null) {
             // we don't know what the root is; so use possibleRoots...
             int chunk, index = 0;
             String currName = null;
-            Vector elements = new Vector();
-            for (int i=0; i < fElementDeclCount; i++) {
+            final int size = fElementDeclCount;
+            ArrayList elements = new ArrayList(size);
+            for (int i = 0; i < size; ++i) {
                 chunk = i >> CHUNK_SHIFT;
                 index = i & CHUNK_MASK;
                 currName = fElementDeclName[chunk][index].rawname;
-                elements.addElement(currName);
+                elements.add(currName);
             }
             fGrammarDescription.setPossibleRoots(elements);
         }

Modified: xerces/java/trunk/src/org/apache/xerces/impl/dtd/XMLDTDDescription.java
URL: http://svn.apache.org/viewvc/xerces/java/trunk/src/org/apache/xerces/impl/dtd/XMLDTDDescription.java?rev=606543&r1=606542&r2=606543&view=diff
==============================================================================
--- xerces/java/trunk/src/org/apache/xerces/impl/dtd/XMLDTDDescription.java (original)
+++ xerces/java/trunk/src/org/apache/xerces/impl/dtd/XMLDTDDescription.java Sat Dec 22 22:38:17 2007
@@ -22,6 +22,8 @@
 import org.apache.xerces.xni.parser.XMLInputSource;
 
 import org.apache.xerces.util.XMLResourceIdentifierImpl;
+
+import java.util.ArrayList;
 import java.util.Vector;
 
 /**
@@ -43,7 +45,7 @@
 
     // if we don't know the root name, this stores all elements that
     // could serve; fPossibleRoots and fRootName cannot both be non-null
-    protected Vector fPossibleRoots = null;
+    protected ArrayList fPossibleRoots = null;
 
     // Constructors:
     public XMLDTDDescription(XMLResourceIdentifier id, String rootName) {
@@ -85,11 +87,16 @@
         fRootName = rootName;
         fPossibleRoots = null;
     }
+    
+    /** Set possible roots **/
+    public void setPossibleRoots(ArrayList possibleRoots) {
+        fPossibleRoots = possibleRoots;
+    }
 
     /** Set possible roots **/
     public void setPossibleRoots(Vector possibleRoots) {
-        fPossibleRoots = possibleRoots;
-    } 
+        fPossibleRoots = (possibleRoots != null) ? new ArrayList(possibleRoots) : null;
+    }
 
     /**
      * Compares this grammar with the given grammar. Currently, we compare 
@@ -105,49 +112,58 @@
      * @return     True if they are equal, else false
      */
     public boolean equals(Object desc) {
-        if(!(desc instanceof XMLGrammarDescription)) return false;
+        if (!(desc instanceof XMLGrammarDescription)) return false;
     	if (!getGrammarType().equals(((XMLGrammarDescription)desc).getGrammarType())) {
     	    return false;
     	}
         // assume it's a DTDDescription
         XMLDTDDescription dtdDesc = (XMLDTDDescription)desc;
-        if(fRootName != null) {
-            if((dtdDesc.fRootName) != null && !dtdDesc.fRootName.equals(fRootName)) {
+        if (fRootName != null) {
+            if ((dtdDesc.fRootName) != null && !dtdDesc.fRootName.equals(fRootName)) {
                 return false;
-            } else if(dtdDesc.fPossibleRoots != null && !dtdDesc.fPossibleRoots.contains(fRootName)) {
+            } 
+            else if (dtdDesc.fPossibleRoots != null && !dtdDesc.fPossibleRoots.contains(fRootName)) {
                 return false;
             }
-        } else if(fPossibleRoots != null) {
-            if(dtdDesc.fRootName != null) {
-                if(!fPossibleRoots.contains(dtdDesc.fRootName)) { 
+        } 
+        else if (fPossibleRoots != null) {
+            if (dtdDesc.fRootName != null) {
+                if (!fPossibleRoots.contains(dtdDesc.fRootName)) { 
                     return false;
                 }
-            } else if(dtdDesc.fPossibleRoots == null) {
+            } 
+            else if (dtdDesc.fPossibleRoots == null) {
                 return false;
-            } else {
+            } 
+            else {
                 boolean found = false;
-                for(int i = 0; i<fPossibleRoots.size(); i++) {
-                    String root = (String)fPossibleRoots.elementAt(i);
+                final int size = fPossibleRoots.size();
+                for (int i = 0; i < size; ++i) {
+                    String root = (String) fPossibleRoots.get(i);
                     found = dtdDesc.fPossibleRoots.contains(root);
-                    if(found) break;
+                    if (found) break;
                 }
-                if(!found) return false;
+                if (!found) return false;
             }
         }
         // if we got this far we've got a root match... try other two fields,
         // since so many different DTD's have roots in common:
-        if(fExpandedSystemId != null) {
-            if(!fExpandedSystemId.equals(dtdDesc.fExpandedSystemId)) 
+        if (fExpandedSystemId != null) {
+            if (!fExpandedSystemId.equals(dtdDesc.fExpandedSystemId)) {
                 return false;
+            }
         } 
-        else if(dtdDesc.fExpandedSystemId != null)
+        else if (dtdDesc.fExpandedSystemId != null) {
             return false;
-        if(fPublicId != null) {
-            if(!fPublicId.equals(dtdDesc.fPublicId)) 
+        }
+        if (fPublicId != null) {
+            if (!fPublicId.equals(dtdDesc.fPublicId)) {
                 return false;
+            }
         } 
-        else if(dtdDesc.fPublicId != null)
+        else if (dtdDesc.fPublicId != null) {
             return false;
+        }
     	return true;
     }
     
@@ -158,10 +174,12 @@
      * @return The hash code
      */
     public int hashCode() {
-        if(fExpandedSystemId != null)
+        if (fExpandedSystemId != null) {
             return fExpandedSystemId.hashCode();
-        if(fPublicId != null)
+        }
+        if (fPublicId != null) {
             return fPublicId.hashCode();
+        }
         // give up; hope .equals can handle it:
         return 0;
     }



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@xerces.apache.org
For additional commands, e-mail: commits-help@xerces.apache.org