mkwan 2003/01/31 12:31:34
Modified: java/src/org/apache/xalan/xsltc/dom Tag: XSLTC_DTM
SAXImpl.java
java/src/org/apache/xml/dtm/ref/sax2dtm Tag: XSLTC_DTM
SAX2DTM.java SAX2DTM2.java
Log:
XSLTC_DTM performance work
Override the following interfaces in SAX2DTM2 to provide optimized
implementations:
DTMDefaultBase.getFirstAttribute(int)
DTMDefaultBase.getTypedAttribute(int, int)
SAX2DTM.getNodeNameX(int)
Implement the interface getStringValueX() in SAX2DTM2 which replaces
SAX2DTM.getStringValue(). The new interface returns a String instead of
a XMLString. The use of XMLString in XSLTC is now deprecated.
Revision Changes Path
No revision
No revision
1.1.2.27 +6 -5
xml-xalan/java/src/org/apache/xalan/xsltc/dom/Attic/SAXImpl.java
Index: SAXImpl.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/dom/Attic/SAXImpl.java,v
retrieving revision 1.1.2.26
retrieving revision 1.1.2.27
diff -u -r1.1.2.26 -r1.1.2.27
--- SAXImpl.java 29 Jan 2003 22:03:28 -0000 1.1.2.26
+++ SAXImpl.java 31 Jan 2003 20:31:33 -0000 1.1.2.27
@@ -819,11 +819,11 @@
/**
* Returns the (String) value of any node in the tree
- */
+
public String getStringValueX(final int node)
{
if (node == DTM.NULL) return EMPTYSTRING;
-/*
+
switch(getNodeType(node)) {
case DTM.ROOT_NODE:
case DTM.DOCUMENT_NODE:
@@ -838,9 +838,10 @@
default:
return getStringValue(node).toString();
}
-*/
+
return getStringValue(node).toString();
- }
+ }
+ */
/**
* Sets up a translet-to-dom type mapping table
No revision
No revision
1.28.2.15 +1 -1
xml-xalan/java/src/org/apache/xml/dtm/ref/sax2dtm/SAX2DTM.java
Index: SAX2DTM.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xml/dtm/ref/sax2dtm/SAX2DTM.java,v
retrieving revision 1.28.2.14
retrieving revision 1.28.2.15
diff -u -r1.28.2.14 -r1.28.2.15
--- SAX2DTM.java 29 Jan 2003 17:13:20 -0000 1.28.2.14
+++ SAX2DTM.java 31 Jan 2003 20:31:34 -0000 1.28.2.15
@@ -166,7 +166,7 @@
protected DTMTreeWalker m_walker = new DTMTreeWalker();
/** pool of string values that come as strings. */
- private DTMStringPool m_valuesOrPrefixes = new DTMStringPool();
+ protected DTMStringPool m_valuesOrPrefixes = new DTMStringPool();
/** End document has been reached.
* Made protected rather than private so SAX2RTFDTM can access it.
1.1.2.3 +231 -5
xml-xalan/java/src/org/apache/xml/dtm/ref/sax2dtm/Attic/SAX2DTM2.java
Index: SAX2DTM2.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xml/dtm/ref/sax2dtm/Attic/SAX2DTM2.java,v
retrieving revision 1.1.2.2
retrieving revision 1.1.2.3
diff -u -r1.1.2.2 -r1.1.2.3
--- SAX2DTM2.java 31 Jan 2003 16:30:17 -0000 1.1.2.2
+++ SAX2DTM2.java 31 Jan 2003 20:31:34 -0000 1.1.2.3
@@ -1549,6 +1549,8 @@
protected final int m_SHIFT;
protected final int m_MASK;
+ // A constant for empty string
+ private static final String EMPTY_STR = "";
/**
* Construct a SAX2DTM2 object using the default block size.
@@ -1645,12 +1647,12 @@
/**
* The optimized version of DTMDefaultBase._type().
*/
- public final short _type2(int identity)
+ public final int _type2(int identity)
{
- int info = _exptype2(identity);
+ int eType = _exptype2(identity);
- if (NULL != info)
- return m_expandedNameTable.getType(info);
+ if (NULL != eType)
+ return m_extendedTypes[eType].getNodeType();
else
return NULL;
}
@@ -1666,9 +1668,12 @@
{
super.endDocument();
- // Add a NULL entry to the end of the m_exptype array as
+ // Add a NULL entry to the end of the node arrays as
// the end indication.
m_exptype.addElement(NULL);
+ m_parent.addElement(NULL);
+ m_nextsib.addElement(NULL);
+ m_firstch.addElement(NULL);
// Set the cached references after the document is built.
m_extendedTypes = m_expandedNameTable.getExtendedTypes();
@@ -1678,4 +1683,225 @@
m_parent_map = m_parent.getMap();
}
+ /**
+ * The optimized version of DTMDefaultBase.getNodeType().
+ *
+ * Given a node handle, return its DOM- style node type.
+ *
+ * @param nodeHandle The node id.
+ * @return int Node type, as per the DOM's Node._NODE constants.
+ */
+ public final int getNodeType2(int nodeHandle)
+ {
+ if (nodeHandle == DTM.NULL)
+ return DTM.NULL;
+ else
+ return
m_extendedTypes[_exptype2(makeNodeIdentity(nodeHandle))].getNodeType();
+ }
+
+ /**
+ * The optimized version of DTMDefaultBase.getFirstAttribute().
+ *
+ * Given a node handle, get the index of the node's first attribute.
+ *
+ * @param nodeHandle int Handle of the node.
+ * @return Handle of first attribute, or DTM.NULL to indicate none exists.
+ */
+ public final int getFirstAttribute(int nodeHandle)
+ {
+ int nodeID = makeNodeIdentity(nodeHandle);
+
+ if (nodeID == DTM.NULL)
+ return DTM.NULL;
+
+ int type = _type2(nodeID);
+
+ if (DTM.ELEMENT_NODE == type)
+ {
+ // Assume that attributes and namespaces immediately follow the
element.
+ while (true)
+ {
+ nodeID++;
+ // Assume this can not be null.
+ type = _type2(nodeID);
+
+ if (type == DTM.ATTRIBUTE_NODE)
+ {
+ return makeNodeHandle(nodeID);
+ }
+ else if (DTM.NAMESPACE_NODE != type)
+ {
+ break;
+ }
+ }
+ }
+
+ return DTM.NULL;
+ }
+
+ /**
+ * The optimized version of DTMDefaultBase.getTypedAttribute(int, int).
+ *
+ * Given a node handle and an expanded type ID, get the index of the node's
+ * attribute of that type, if any.
+ *
+ * @param nodeHandle int Handle of the node.
+ * @param attType int expanded type ID of the required attribute.
+ * @return Handle of attribute of the required type, or DTM.NULL to
indicate
+ * none exists.
+ */
+ protected final int getTypedAttribute(int nodeHandle, int attType)
+ {
+
+ int nodeID = makeNodeIdentity(nodeHandle);
+
+ if (nodeID == DTM.NULL)
+ return DTM.NULL;
+
+ int type = _type2(nodeID);
+
+ if (DTM.ELEMENT_NODE == type)
+ {
+ int expType;
+ while (true)
+ {
+ nodeID++;
+ expType = _exptype2(nodeID);
+
+ if (expType != DTM.NULL)
+ type = m_extendedTypes[expType].getNodeType();
+ else
+ return DTM.NULL;
+
+ if (type == DTM.ATTRIBUTE_NODE)
+ {
+ if (expType == attType) return makeNodeHandle(nodeID);
+ }
+ else if (DTM.NAMESPACE_NODE != type)
+ {
+ break;
+ }
+ }
+ }
+
+ return DTM.NULL;
+ }
+
+ /**
+ * The optimized version of SAX2DTM.getNodeNameX().
+ *
+ * Given a node handle, return the XPath node name. This should be the
name
+ * as described by the XPath data model, NOT the DOM- style name.
+ *
+ * @param nodeHandle the id of the node.
+ * @return String Name of this node, which may be an empty string.
+ */
+ public final String getNodeNameX(int nodeHandle)
+ {
+
+ int nodeID = makeNodeIdentity(nodeHandle);
+ int eType = _exptype2(nodeID);
+ final ExtendedType extType = m_extendedTypes[eType];
+
+ if (extType.getNamespace().length() == 0)
+ {
+ return extType.getLocalName();
+ }
+ else
+ {
+ int qnameIndex = m_dataOrQName.elementAt(nodeID);
+
+ if (qnameIndex < 0)
+ {
+ qnameIndex = -qnameIndex;
+ qnameIndex = m_data.elementAt(qnameIndex);
+ }
+
+ return m_valuesOrPrefixes.indexToString(qnameIndex);
+ }
+ }
+
+ /**
+ * The optimized version of SAX2DTM.getStringValue(int).
+ *
+ * %OPT% This is one of the most often used interfaces. Performance is
+ * critical here. This one is different from SAX2DTM.getStringValue(int) in
+ * that it returns a String instead of a XMLString.
+ *
+ * Get the string- value of a node as a String object (see http: //www. w3.
+ * org/TR/xpath#data- model for the definition of a node's string- value).
+ *
+ * @param nodeHandle The node ID.
+ *
+ * @return A string object that represents the string-value of the given
node.
+ */
+ public final String getStringValueX(final int nodeHandle)
+ {
+ int identity = makeNodeIdentity(nodeHandle);
+ if (identity == DTM.NULL)
+ return EMPTY_STR;
+
+ int type= _type2(identity);
+
+ if (type == DTM.ELEMENT_NODE || type == DTM.DOCUMENT_NODE)
+ {
+ int firstChild = _firstch2(identity);
+ if (DTM.NULL != firstChild)
+ {
+ int offset = -1;
+ int length = 0;
+ int startNode = identity;
+
+ identity = firstChild;
+
+ do
+ {
+ type = _exptype2(identity);
+
+ if (type == DTM.TEXT_NODE || type == DTM.CDATA_SECTION_NODE)
+ {
+ int dataIndex = _dataOrQName(identity);
+
+ if (-1 == offset)
+ {
+ offset = m_data.elementAt(dataIndex);
+ }
+
+ length += m_data.elementAt(dataIndex + 1);
+ }
+
+ identity++;
+ } while (_parent2(identity) >= startNode);
+
+ if (length > 0)
+ {
+ return m_chars.getString(offset, length);
+ }
+ else
+ return EMPTY_STR;
+ }
+ else
+ return EMPTY_STR;
+ }
+ else if (DTM.TEXT_NODE == type || DTM.CDATA_SECTION_NODE == type)
+ {
+ int dataIndex = _dataOrQName(identity);
+ int offset = m_data.elementAt(dataIndex);
+ int length = m_data.elementAt(dataIndex + 1);
+
+ return m_chars.getString(offset, length);
+ }
+ else
+ {
+ int dataIndex = _dataOrQName(identity);
+
+ if (dataIndex < 0)
+ {
+ dataIndex = -dataIndex;
+ dataIndex = m_data.elementAt(dataIndex + 1);
+ }
+ return m_valuesOrPrefixes.indexToString(dataIndex);
+ }
+ }
+
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]