sboag 00/12/13 13:54:45
Modified: java/src/org/apache/xpath/axes AttributeWalker.java
ChildTestIterator.java LocPathIterator.java
WalkerFactory.java
Log:
Implemented fast iterator for "@foo" pattern.
Revision Changes Path
1.4 +3 -3
xml-xalan/java/src/org/apache/xpath/axes/AttributeWalker.java
Index: AttributeWalker.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xpath/axes/AttributeWalker.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- AttributeWalker.java 2000/10/30 18:58:43 1.3
+++ AttributeWalker.java 2000/12/13 21:54:43 1.4
@@ -149,13 +149,13 @@
return null;
}
- /** NEEDSDOC Field m_attributeList */
+ /** The attribute list for the given context. */
NamedNodeMap m_attributeList;
- /** NEEDSDOC Field m_attrListPos */
+ /** The position within the attribute list. */
int m_attrListPos;
- /** NEEDSDOC Field m_nAttrs */
+ /** The number of attributes within the list. */
int m_nAttrs;
/**
1.3 +23 -15
xml-xalan/java/src/org/apache/xpath/axes/ChildTestIterator.java
Index: ChildTestIterator.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xpath/axes/ChildTestIterator.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- ChildTestIterator.java 2000/11/23 04:59:00 1.2
+++ ChildTestIterator.java 2000/12/13 21:54:43 1.3
@@ -68,20 +68,21 @@
/**
* <meta name="usage" content="advanced"/>
- * This class implements an optimized iterator for
- * "node()" patterns, that is, any children of the
- * context node.
+ * This class implements an optimized iterator for
+ * children patterns that have a node test, but no predicate.
* @see org.apache.xpath.axes.WalkerFactory#newLocPathIterator.
*/
public class ChildTestIterator extends LocPathIterator
{
+
+ /** The NodeTest for this iterator. */
NodeTest m_nodeTest;
/**
* Create a ChildTestIterator object.
*
* @param compiler A reference to the Compiler that contains the op map.
- * @param opPos The position within the op map, which contains the
+ * @param opPos The position within the op map, which contains the
* location path expression for this itterator.
*
* @throws javax.xml.transform.TransformerException
@@ -89,10 +90,14 @@
public ChildTestIterator(Compiler compiler, int opPos)
throws javax.xml.transform.TransformerException
{
+
super(compiler, opPos, false);
+
m_nodeTest = new NodeTest();
+
int firstStepPos = compiler.getFirstChildPos(opPos);
int whatToShow = compiler.getWhatToShow(firstStepPos);
+
if ((0 == (whatToShow
& (NodeFilter.SHOW_ATTRIBUTE | NodeFilter.SHOW_ELEMENT
| NodeFilter.SHOW_PROCESSING_INSTRUCTION))) || (whatToShow
== NodeFilter.SHOW_ALL))
@@ -108,10 +113,10 @@
* Returns the next node in the set and advances the position of the
* iterator in the set. After a NodeIterator is created, the first call
* to nextNode() returns the first node in the set.
- *
+ *
* @return The next <code>Node</code> in the set being iterated over, or
* <code>null</code> if there are no more members in that set.
- *
+ *
* @exception DOMException
* INVALID_STATE_ERR: Raised if this method is called after the
* <code>detach</code> method was invoked.
@@ -135,22 +140,25 @@
return null;
Node next;
+
do
{
m_lastFetched = next = (null == m_lastFetched)
? m_context.getFirstChild()
- : m_lastFetched.getNextSibling();
- if(null != next)
+ : m_lastFetched.getNextSibling();
+
+ if (null != next)
{
try
{
- XObject score = m_nodeTest.execute(m_execContext, next);
- if(NodeTest.SCORE_NONE == score)
- continue;
- else
- break;
+ XObject score = m_nodeTest.execute(m_execContext, next);
+
+ if (NodeTest.SCORE_NONE == score)
+ continue;
+ else
+ break;
}
- catch(TransformerException te)
+ catch (TransformerException te)
{
throw new org.apache.xml.utils.WrappedRuntimeException(te);
}
@@ -158,7 +166,7 @@
else
break;
}
- while(next != null);
+ while (next != null);
if (null != next)
{
1.18 +1 -1
xml-xalan/java/src/org/apache/xpath/axes/LocPathIterator.java
Index: LocPathIterator.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xpath/axes/LocPathIterator.java,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -r1.17 -r1.18
--- LocPathIterator.java 2000/12/09 03:56:47 1.17
+++ LocPathIterator.java 2000/12/13 21:54:43 1.18
@@ -599,7 +599,7 @@
*/
public Object clone() throws CloneNotSupportedException
{
-
+
LocPathIterator clone = (LocPathIterator) super.clone();
clone.m_varStackPos = this.m_varStackPos;
clone.m_varStackContext = this.m_varStackContext;
1.8 +16 -17
xml-xalan/java/src/org/apache/xpath/axes/WalkerFactory.java
Index: WalkerFactory.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xpath/axes/WalkerFactory.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- WalkerFactory.java 2000/11/16 20:04:50 1.7
+++ WalkerFactory.java 2000/12/13 21:54:43 1.8
@@ -185,6 +185,10 @@
{
return new ChildTestIterator(compiler, opPos);
}
+ else if(ONESTEP_ATTR_NO_PREDICATES == analysis)
+ {
+ return new AttributeIterator(compiler, opPos);
+ }
else
{
return new LocPathIterator(compiler, opPos, true);
@@ -194,36 +198,27 @@
// There is no optimized walker that can handle
// this pattern, so use the default.
- /** NEEDSDOC Field NO_OPTIMIZE */
+ /** Pattern that we do not optimize for. */
static final int NO_OPTIMIZE = 1;
-
- // "."
- /** NEEDSDOC Field ONESTEP_SELF */
+ /** "." */
static final int ONESTEP_SELF = 2;
- // "*"
-
- /** NEEDSDOC Field ONESTEP_CHILDREN */
+ /** "*" */
static final int ONESTEP_CHILDREN = 3;
- // "*"
-
- /** NEEDSDOC Field ONESTEP_CHILDREN_ANY */
+ /** "node()" */
static final int ONESTEP_CHILDREN_ANY = 7;
-
- // "foo"
- /** NEEDSDOC Field ONESTEP_ATTR */
+ /** "@foo[../baz]" */
static final int ONESTEP_ATTR = 4;
- // "//foo"
+ /** "@foo" */
+ static final int ONESTEP_ATTR_NO_PREDICATES = 9;
/** NEEDSDOC Field ONESTEP_DESCENDANTS */
static final int ONESTEP_DESCENDANTS = 5;
- // "foo/baz/boo"
-
/** NEEDSDOC Field MULTISTEP_CHILDREN */
static final int MULTISTEP_CHILDREN = 6;
@@ -277,7 +272,10 @@
case OpCodes.FROM_ATTRIBUTES :
if (1 == stepCount)
{
- analysisResult = ONESTEP_ATTR;
+ if(predAnalysis == HAS_NOPREDICATE)
+ analysisResult = ONESTEP_ATTR_NO_PREDICATES;
+ else
+ analysisResult = ONESTEP_ATTR;
}
else
{
@@ -451,6 +449,7 @@
case OpCodes.FROM_ATTRIBUTES :
switch (analysis)
{
+ case ONESTEP_ATTR_NO_PREDICATES:
case ONESTEP_ATTR :
ai = new AttributeWalkerOneStep(lpi);
break;