mmidy 02/05/09 15:09:09
Modified: java/src/org/apache/xml/dtm/ref ExpandedNameTable.java
Log:
Performance improvement. Instead of looping through the ExtendedType objects,
use a hashtable and go directly to the correct object.
Revision Changes Path
1.5 +72 -24
xml-xalan/java/src/org/apache/xml/dtm/ref/ExpandedNameTable.java
Index: ExpandedNameTable.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xml/dtm/ref/ExpandedNameTable.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- ExpandedNameTable.java 10 Apr 2002 20:33:16 -0000 1.4
+++ ExpandedNameTable.java 9 May 2002 22:09:09 -0000 1.5
@@ -59,6 +59,7 @@
import org.apache.xml.dtm.DTM;
import java.util.Vector;
+import java.util.Hashtable;
/**
* This is a default implementation of a table that manages mappings from
@@ -104,6 +105,12 @@
public static final int NOTATION = ((int)DTM.NOTATION_NODE) ;
public static final int NAMESPACE = ((int)DTM.NAMESPACE_NODE) ;
+ Hashtable m_hashtable = new Hashtable();
+
+ /** Workspace for lookup. NOT THREAD SAFE!
+ * */
+ ExtendedType hashET=new ExtendedType(-1,"","");
+
/**
* Create an expanded name table that uses private string pool lookup.
@@ -166,15 +173,21 @@
*/
if (null == namespace)
namespace = "";
- if (null == localName)
+ if (null == localName)
localName = "";
- for (int i = 0; i < m_extendedTypes.size(); i++)
- {
- ExtendedType etype = (ExtendedType)m_extendedTypes.elementAt(i);
- if( type == etype.nodetype && namespace.equals(etype.namespace) &&
localName.equals(etype.localName))
- return i;
- }
- m_extendedTypes.addElement(new ExtendedType(type, namespace, localName));
+ // Set our reusable ExpandedType so we can look
+ // it up in the hashtable. Not threadsafe, but
+ // avoids creating a new object until we know
+ // this isn't one we've seen before.
+ hashET.redefine(type,namespace,localName);
+
+ Object eType;
+ if ((eType = m_hashtable.get(hashET)) != null )
+ return ((Integer)eType).intValue();
+
+ ExtendedType newET=new ExtendedType(type, namespace, localName);
+ m_extendedTypes.addElement(newET);
+ m_hashtable.put(newET, new Integer(m_nextType));
return m_nextType++;
}
@@ -188,18 +201,8 @@
* @return the expanded-name id of the node.
*/
public int getExpandedTypeID(int type)
- {
- /*int expandedTypeID = (type << (BITS_PER_NAMESPACE+BITS_PER_LOCALNAME));
-
- return expandedTypeID;
- */
- for (int i = 0; i < m_extendedTypes.size(); i++)
- {
- ExtendedType etype = (ExtendedType)m_extendedTypes.elementAt(i);
- if( type == etype.nodetype )
- return i;
- }
- return -1; // something's very wrong!
+ {
+ return type;
}
/**
@@ -283,16 +286,61 @@
*/
private class ExtendedType
{
- private int nodetype;
- private String namespace;
- private String localName;
+ protected int nodetype;
+ protected String namespace;
+ protected String localName;
+ protected int hash;
- private ExtendedType (int nodetype, String namespace, String localName)
+ protected ExtendedType (int nodetype, String namespace, String localName)
{
this.nodetype = nodetype;
this.namespace = namespace;
this.localName = localName;
+ this.hash=nodetype+namespace.hashCode()+localName.hashCode();
}
+
+ /* This is intended to be used ONLY on the hashET
+ * object. Using it elsewhere will mess up existing
+ * hashtable entries!
+ * */
+ protected void redefine(int nodetype, String namespace, String localName)
+ {
+ this.nodetype = nodetype;
+ this.namespace = namespace;
+ this.localName = localName;
+ this.hash=nodetype+namespace.hashCode()+localName.hashCode();
+ }
+
+ /* Override super method
+ * */
+ public int hashCode()
+ {
+ return hash;
+ }
+
+ /* Override super method
+ * */
+ public boolean equals(Object other)
+ {
+ //Usually an optimization, but
+ // won't arise in our usage:
+ //if(other==this) return true;
+ try
+ {
+ ExtendedType et=(ExtendedType)other;
+ return et.nodetype==this.nodetype &&
+ et.localName.equals(this.localName) &&
+ et.namespace.equals(this.namespace);
+ }
+ catch(ClassCastException e)
+ {
+ return false;
+ }
+ catch(NullPointerException e)
+ {
+ return false;
+ }
+ }
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]