ilene 2002/10/19 17:54:43
Modified: java/src/org/apache/xml/dtm/ref ExpandedNameTable.java
Log:
Committing Pavel Ausianik's ([EMAIL PROTECTED]) patch for bugzilla #12687.
Reduce memory allocation on initialization of ExpandedNameTable.
m_locNamesPool and m_namespaceNames and code that uses them has
been commented out. Some initialization now done in static initializer.
Revision Changes Path
1.7 +88 -74
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.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- ExpandedNameTable.java 10 May 2002 18:41:54 -0000 1.6
+++ ExpandedNameTable.java 20 Oct 2002 00:54:43 -0000 1.7
@@ -2,7 +2,7 @@
* The Apache Software License, Version 1.1
*
*
- * Copyright (c) 1999 The Apache Software Foundation. All rights
+ * Copyright (c) 1999 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -10,7 +10,7 @@
* are met:
*
* 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
+ * notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
@@ -18,7 +18,7 @@
* distribution.
*
* 3. The end-user documentation included with the redistribution,
- * if any, must include the following acknowledgment:
+ * if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
@@ -26,7 +26,7 @@
*
* 4. The names "Xalan" and "Apache Software Foundation" must
* not be used to endorse or promote products derived from this
- * software without prior written permission. For written
+ * software without prior written permission. For written
* permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache",
@@ -79,17 +79,17 @@
{
/** Probably a reference to static pool. */
- private DTMStringPool m_locNamesPool;
+ //private DTMStringPool m_locNamesPool;
/** Probably a reference to static pool. */
- private DTMStringPool m_namespaceNames;
-
+ //private DTMStringPool m_namespaceNames;
+
/** Vector of extended types for this document */
private /*static*/ Vector m_extendedTypes;
-
+
/** Next available extended type */
private int m_nextType;
-
+
// These are all the types prerotated, for caller convenience.
public static final int ELEMENT = ((int)DTM.ELEMENT_NODE) ;
public static final int ATTRIBUTE = ((int)DTM.ATTRIBUTE_NODE) ;
@@ -104,22 +104,40 @@
public static final int DOCUMENT_FRAGMENT
=((int)DTM.DOCUMENT_FRAGMENT_NODE) ;
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,"","");
-
+
+ /** Workspace for lookup. NOT THREAD SAFE!
+ * */
+ ExtendedType hashET=new ExtendedType(-1,"","");
+
+ private static Hashtable m_defaultHashtable;
+ private static Vector m_defaultExtendedTypes;
+
+ /**
+ * Init default vales
+ */
+ static {
+ // use bigger values than default, to avoid reallocation in the future
+ m_defaultExtendedTypes = new Vector(23);
+ m_defaultHashtable = new Hashtable(23, 0.75f);
+
+ for (int i = 0; i < DTM.NTYPES; i++)
+ {
+ ExtendedType newET = new ExtendedType(i, "", "");
+ m_defaultExtendedTypes.addElement(newET);
+ m_defaultHashtable.put(newET, new Integer(i));
+ }
+ }
/**
* Create an expanded name table that uses private string pool lookup.
*/
public ExpandedNameTable()
{
- m_locNamesPool = new DTMSafeStringPool();
- m_namespaceNames = new DTMSafeStringPool();
- initExtendedTypes();
+ //m_locNamesPool = new DTMSafeStringPool();
+ //m_namespaceNames = new DTMSafeStringPool();
+ initExtendedTypes();
}
/**
@@ -131,25 +149,21 @@
public ExpandedNameTable(DTMStringPool locNamesPool,
DTMStringPool namespaceNames)
{
- m_locNamesPool = locNamesPool;
- m_namespaceNames = namespaceNames;
+ //m_locNamesPool = locNamesPool;
+ //m_namespaceNames = namespaceNames;
initExtendedTypes();
}
-
+
/**
- * Initialize the vector of extended types with the
- * basic DOM node types.
+ * Initialize the vector of extended types with the
+ * basic DOM node types.
*/
private void initExtendedTypes()
{
- m_extendedTypes = new Vector();
- int i;
- for (i = 0; i < DTM.NTYPES; i++)
- {
- ExtendedType newET = new ExtendedType(i, "", "");
- m_extendedTypes.addElement(newET);
- m_hashtable.put(newET, new Integer(i));
- }
+ // Since objects in the Vector a m_extendedTypes and m_hashtable are
never changed
+ // it should be safe to copy default tables
+ m_extendedTypes = (Vector)m_defaultExtendedTypes.clone();
+ m_hashtable = (Hashtable)m_defaultHashtable.clone();
m_nextType = m_extendedTypes.size();
}
@@ -168,33 +182,33 @@
{
/*int nsID = (null != namespace) ?
m_namespaceNames.stringToIndex(namespace) : 0;
int lnID = m_locNamesPool.stringToIndex(localName);
-
- int expandedTypeID = (type << (BITS_PER_NAMESPACE+BITS_PER_LOCALNAME))
+
+ int expandedTypeID = (type << (BITS_PER_NAMESPACE+BITS_PER_LOCALNAME))
| (nsID << BITS_PER_LOCALNAME) | lnID;
return expandedTypeID;
*/
- if (null == namespace)
+ if (null == namespace)
namespace = "";
- if (null == localName)
+ if (null == localName)
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++;
}
-
+
/**
- * Given a type, return an expanded name ID.Any additional nodes that are
+ * Given a type, return an expanded name ID.Any additional nodes that are
* created that have this expanded name will use this ID.
*
* @param namespace
@@ -203,8 +217,8 @@
* @return the expanded-name id of the node.
*/
public int getExpandedTypeID(int type)
- {
- return type;
+ {
+ return type;
}
/**
@@ -219,7 +233,7 @@
ExtendedType etype = (ExtendedType)m_extendedTypes.elementAt
(ExpandedNameID);
return etype.localName;
}
-
+
/**
* Given an expanded-name ID, return the local name ID.
*
@@ -250,9 +264,9 @@
//int id = (ExpandedNameID & MASK_NAMESPACE) >> BITS_PER_LOCALNAME;
//return (0 == id) ? null : m_namespaceNames.indexToString(id);
ExtendedType etype = (ExtendedType)m_extendedTypes.elementAt
(ExpandedNameID);
- return (etype.namespace.equals("") ? null : etype.namespace);
+ return (etype.namespace.equals("") ? null : etype.namespace);
}
-
+
/**
* Given an expanded-name ID, return the namespace URI ID.
*
@@ -268,7 +282,7 @@
else
return ExpandedNameID;
}
-
+
/**
* Given an expanded-name ID, return the local name ID.
*
@@ -281,18 +295,18 @@
ExtendedType etype = (ExtendedType)m_extendedTypes.elementAt
(ExpandedNameID);
return (short)etype.nodetype;
}
-
-
+
+
/**
- * Private class representing an extended type object
+ * Private class representing an extended type object
*/
- private class ExtendedType
+ private static class ExtendedType
{
protected int nodetype;
protected String namespace;
protected String localName;
protected int hash;
-
+
protected ExtendedType (int nodetype, String namespace, String localName)
{
this.nodetype = nodetype;
@@ -312,37 +326,37 @@
this.localName = localName;
this.hash=nodetype+namespace.hashCode()+localName.hashCode();
}
-
+
/* Override super method
* */
- public int hashCode()
+ 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;
- }
- }
+ 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]