sboag 01/07/27 17:45:05
Modified: java/src/org/apache/xpath Expression.java
java/src/org/apache/xpath/axes AxesWalker.java
LocPathIterator.java PredicatedNodeTest.java
ReverseAxesWalker.java
java/src/org/apache/xpath/objects XNumber.java
java/src/org/apache/xpath/operations Variable.java
Log:
If a proximity predicate is a stable number (variable or number literal) then,
once the node is found, don't keep searching! (since only one
node is possible).
Revision Changes Path
1.17 +98 -63 xml-xalan/java/src/org/apache/xpath/Expression.java
Index: Expression.java
===================================================================
RCS file: /home/cvs/xml-xalan/java/src/org/apache/xpath/Expression.java,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -r1.16 -r1.17
--- Expression.java 2001/06/15 17:54:17 1.16
+++ Expression.java 2001/07/28 00:45:05 1.17
@@ -57,7 +57,6 @@
package org.apache.xpath;
//import org.w3c.dom.Node;
-
import org.apache.xpath.objects.XObject;
import org.apache.xpath.res.XPATHErrorResources;
import org.apache.xalan.res.XSLMessages;
@@ -95,32 +94,32 @@
* @serial
*/
protected SourceLocator m_slocator;
-
+
/**
- * Tell if this expression or it's subexpressions can traverse outside
+ * Tell if this expression or it's subexpressions can traverse outside
* the current subtree.
- *
+ *
* @return true if traversal outside the context node's subtree can occur.
*/
- public boolean canTraverseOutsideSubtree()
- {
+ public boolean canTraverseOutsideSubtree()
+ {
return false;
- }
+ }
/**
* Set the location where this expression was built from.
*
*
- * @param locator the location where this expression was built from, may
be
+ * @param locator the location where this expression was built from, may be
* null.
*/
public void setSourceLocator(SourceLocator locator)
{
m_slocator = locator;
}
-
+
/**
- * Execute an expression in the XPath runtime context, and return the
+ * Execute an expression in the XPath runtime context, and return the
* result of the expression.
*
*
@@ -129,18 +128,19 @@
*
* @return The result of the expression in the form of a
<code>XObject</code>.
*
- * @throws javax.xml.transform.TransformerException if a runtime exception
+ * @throws javax.xml.transform.TransformerException if a runtime exception
* occurs.
*/
public XObject execute(XPathContext xctxt, int currentNode)
- throws javax.xml.transform.TransformerException
+ throws javax.xml.transform.TransformerException
{
+
// For now, the current node is already pushed.
return execute(xctxt);
}
-
+
/**
- * Execute an expression in the XPath runtime context, and return the
+ * Execute an expression in the XPath runtime context, and return the
* result of the expression.
*
*
@@ -151,20 +151,20 @@
*
* @return The result of the expression in the form of a
<code>XObject</code>.
*
- * @throws javax.xml.transform.TransformerException if a runtime exception
+ * @throws javax.xml.transform.TransformerException if a runtime exception
* occurs.
*/
- public XObject execute(XPathContext xctxt, int currentNode,
- DTM dtm, int expType)
- throws javax.xml.transform.TransformerException
+ public XObject execute(
+ XPathContext xctxt, int currentNode, DTM dtm, int expType)
+ throws javax.xml.transform.TransformerException
{
+
// For now, the current node is already pushed.
return execute(xctxt);
}
-
/**
- * Execute an expression in the XPath runtime context, and return the
+ * Execute an expression in the XPath runtime context, and return the
* result of the expression.
*
*
@@ -172,35 +172,38 @@
*
* @return The result of the expression in the form of a
<code>XObject</code>.
*
- * @throws javax.xml.transform.TransformerException if a runtime exception
+ * @throws javax.xml.transform.TransformerException if a runtime exception
* occurs.
*/
public abstract XObject execute(XPathContext xctxt)
throws javax.xml.transform.TransformerException;
-
+
/**
* Evaluate expression to a number.
*
+ *
+ * NEEDSDOC @param xctxt
* @return 0.0
*
* @throws javax.xml.transform.TransformerException
*/
- public double num(XPathContext xctxt)
- throws javax.xml.transform.TransformerException
+ public double num(XPathContext xctxt)
+ throws javax.xml.transform.TransformerException
{
-
return execute(xctxt).num();
}
/**
* Evaluate expression to a boolean.
*
+ *
+ * NEEDSDOC @param xctxt
* @return false
*
* @throws javax.xml.transform.TransformerException
*/
- public boolean bool(XPathContext xctxt)
- throws javax.xml.transform.TransformerException
+ public boolean bool(XPathContext xctxt)
+ throws javax.xml.transform.TransformerException
{
return execute(xctxt).bool();
}
@@ -208,16 +211,20 @@
/**
* Cast result object to a string.
*
+ *
+ * NEEDSDOC @param xctxt
* @return The string this wraps or the empty string if null
+ *
+ * @throws javax.xml.transform.TransformerException
*/
public XMLString xstr(XPathContext xctxt)
- throws javax.xml.transform.TransformerException
+ throws javax.xml.transform.TransformerException
{
return execute(xctxt).xstr();
}
-
+
/**
- * Tell if the expression is a nodeset expression. In other words, tell
+ * Tell if the expression is a nodeset expression. In other words, tell
* if you can execute [EMAIL PROTECTED] asNode() asNode} without an
exception.
* @return true if the expression can be represented as a nodeset.
*/
@@ -225,39 +232,44 @@
{
return false;
}
-
+
/**
- * Return the first node out of the nodeset, if this expression is
+ * Return the first node out of the nodeset, if this expression is
* a nodeset expression.
* @param xctxt The XPath runtime context.
* @return the first node out of the nodeset, or DTM.NULL.
+ *
+ * @throws javax.xml.transform.TransformerException
*/
public int asNode(XPathContext xctxt)
- throws javax.xml.transform.TransformerException
+ throws javax.xml.transform.TransformerException
{
return execute(xctxt).iter().nextNode();
}
-
+
/**
* <meta name="usage" content="experimental"/>
* Given an select expression and a context, evaluate the XPath
* and return the resulting iterator.
- *
+ *
* @param xctxt The execution context.
* @param contextNode The node that "." expresses.
- *
+ *
+ *
+ * NEEDSDOC ($objectName$) @return
* @throws TransformerException thrown if the active ProblemListener
decides
* the error condition is severe enough to halt processing.
*
* @throws javax.xml.transform.TransformerException
*/
- public DTMIterator asIterator(
- XPathContext xctxt, int contextNode)
- throws javax.xml.transform.TransformerException
+ public DTMIterator asIterator(XPathContext xctxt, int contextNode)
+ throws javax.xml.transform.TransformerException
{
+
try
{
xctxt.pushCurrentNodeAndExpression(contextNode, contextNode);
+
return execute(xctxt).iter();
}
finally
@@ -265,53 +277,72 @@
xctxt.popCurrentNodeAndExpression();
}
}
-
+
/**
- * Execute an expression in the XPath runtime context, and return the
+ * Execute an expression in the XPath runtime context, and return the
* result of the expression.
*
*
* @param xctxt The XPath runtime context.
+ * NEEDSDOC @param handler
*
* @return The result of the expression in the form of a
<code>XObject</code>.
*
- * @throws javax.xml.transform.TransformerException if a runtime exception
+ * @throws javax.xml.transform.TransformerException if a runtime exception
* occurs.
+ * @throws org.xml.sax.SAXException
*/
- public void executeCharsToContentHandler(XPathContext xctxt,
- ContentHandler handler)
- throws javax.xml.transform.TransformerException,
- org.xml.sax.SAXException
+ public void executeCharsToContentHandler(
+ XPathContext xctxt, ContentHandler handler)
+ throws javax.xml.transform.TransformerException,
+ org.xml.sax.SAXException
{
+
XObject obj = execute(xctxt);
+
obj.dispatchCharactersEvents(handler);
}
-
+
/**
- * This function is used to fixup variables from QNames to stack frame
+ * Tell if this expression returns a stable number that will not change
during
+ * iterations within the expression. This is used to determine if a
proximity
+ * position predicate can indicate that no more searching has to occur.
+ *
+ *
+ * @return true if the expression represents a stable number.
+ */
+ public boolean isStableNumber()
+ {
+ return false;
+ }
+
+ /**
+ * This function is used to fixup variables from QNames to stack frame
* indexes at stylesheet build time.
- * @param vars List of QNames that correspond to variables. This list
- * should be searched backwards for the first qualified name that
- * corresponds to the variable reference qname. The position of the
- * QName in the vector from the start of the vector will be its position
- * in the stack frame (but variables above the globalsTop value will need
+ * @param vars List of QNames that correspond to variables. This list
+ * should be searched backwards for the first qualified name that
+ * corresponds to the variable reference qname. The position of the
+ * QName in the vector from the start of the vector will be its position
+ * in the stack frame (but variables above the globalsTop value will need
* to be offset to the current stack frame).
+ * NEEDSDOC @param globalsSize
*/
public abstract void fixupVariables(java.util.Vector vars, int
globalsSize);
-
/**
* Warn the user of an problem.
*
* @param xctxt The XPath runtime context.
- * @param msg An error number that corresponds to one of the numbers found
- * in [EMAIL PROTECTED]
org.apache.xpath.res.XPATHErrorResources}, which is
+ * @param msg An error number that corresponds to one of the numbers found
+ * in [EMAIL PROTECTED]
org.apache.xpath.res.XPATHErrorResources}, which is
* a key for a format string.
- * @param args An array of arguments represented in the format string,
which
+ * @param args An array of arguments represented in the format string,
which
* may be null.
*
- * @throws TransformerException if the current ErrorListoner determines to
+ * @throws TransformerException if the current ErrorListoner determines to
* throw an exception.
+ *
+ * @throws javax.xml.transform.TransformerException
*/
public void warn(XPathContext xctxt, int msg, Object[] args)
throws javax.xml.transform.TransformerException
@@ -334,8 +365,10 @@
*
* @param b If false, a runtime exception will be thrown.
* @param msg The assertion message, which should be informative.
- *
+ *
* @throws RuntimeException if the b argument is false.
+ *
+ * @throws javax.xml.transform.TransformerException
*/
public void assertion(boolean b, java.lang.String msg)
throws javax.xml.transform.TransformerException
@@ -356,14 +389,16 @@
* exception.
*
* @param xctxt The XPath runtime context.
- * @param msg An error number that corresponds to one of the numbers found
- * in [EMAIL PROTECTED]
org.apache.xpath.res.XPATHErrorResources}, which is
+ * @param msg An error number that corresponds to one of the numbers found
+ * in [EMAIL PROTECTED]
org.apache.xpath.res.XPATHErrorResources}, which is
* a key for a format string.
- * @param args An array of arguments represented in the format string,
which
+ * @param args An array of arguments represented in the format string,
which
* may be null.
*
- * @throws TransformerException if the current ErrorListoner determines to
+ * @throws TransformerException if the current ErrorListoner determines to
* throw an exception.
+ *
+ * @throws javax.xml.transform.TransformerException
*/
public void error(XPathContext xctxt, int msg, Object[] args)
throws javax.xml.transform.TransformerException
1.20 +4 -6 xml-xalan/java/src/org/apache/xpath/axes/AxesWalker.java
Index: AxesWalker.java
===================================================================
RCS file: /home/cvs/xml-xalan/java/src/org/apache/xpath/axes/AxesWalker.java,v
retrieving revision 1.19
retrieving revision 1.20
diff -u -r1.19 -r1.20
--- AxesWalker.java 2001/06/12 19:16:14 1.19
+++ AxesWalker.java 2001/07/28 00:45:05 1.20
@@ -240,7 +240,7 @@
m_dtm = wi().getXPathContext().getDTM(root);
m_traverser = m_dtm.getAxisTraverser(m_axis);
m_isFresh = true;
- m_isDone = false;
+ m_foundLast = false;
m_root = root;
m_currentNode = root;
m_prevReturned = DTM.NULL;
@@ -340,6 +340,8 @@
*/
protected int getNextNode()
{
+ if (m_foundLast)
+ return DTM.NULL;
if (m_isFresh)
{
@@ -355,7 +357,7 @@
}
if (DTM.NULL == m_currentNode)
- this.m_isDone = true;
+ this.m_foundLast = true;
return m_currentNode;
}
@@ -371,7 +373,6 @@
*/
public int nextNode()
{
-
int nextNode = DTM.NULL;
AxesWalker walker = wi().getLastUsedWalker();
@@ -530,9 +531,6 @@
/** The node last returned from nextNode(). */
transient int m_prevReturned = DTM.NULL;
-
- /** True if this walker has found it's last node. */
- transient boolean m_isDone = false;
/** True if an itteration has not begun. */
transient boolean m_isFresh;
1.31 +0 -3
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.30
retrieving revision 1.31
diff -u -r1.30 -r1.31
--- LocPathIterator.java 2001/07/17 18:17:53 1.30
+++ LocPathIterator.java 2001/07/28 00:45:05 1.31
@@ -1017,9 +1017,6 @@
*/
transient NodeSetDTM m_cachedNodes;
- /** This is true if nextNode returns null. */
- transient protected boolean m_foundLast = false;
-
/**
* The context node for this iterator, which doesn't change through
* the course of the iteration.
1.7 +12 -0
xml-xalan/java/src/org/apache/xpath/axes/PredicatedNodeTest.java
Index: PredicatedNodeTest.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xpath/axes/PredicatedNodeTest.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- PredicatedNodeTest.java 2001/06/24 21:54:49 1.6
+++ PredicatedNodeTest.java 2001/07/28 00:45:05 1.7
@@ -335,6 +335,15 @@
System.out.println("index predicate is true: "+proxPos);
System.out.println("\n===== end predicate count ========");
}
+
+ // If there is a proximity index that will not change during the
+ // course of itteration, then we know there can be no more true
+ // occurances of this predicate, so flag that we're done after
+ // this.
+ if(m_predicates[i].isStableNumber())
+ {
+ m_foundLast = true;
+ }
}
else if (!pred.bool())
return false;
@@ -484,6 +493,9 @@
}
return false;
}
+
+ /** This is true if nextNode returns null. */
+ transient protected boolean m_foundLast = false;
/** The owning location path iterator.
* @serial */
1.8 +3 -1
xml-xalan/java/src/org/apache/xpath/axes/ReverseAxesWalker.java
Index: ReverseAxesWalker.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xpath/axes/ReverseAxesWalker.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- ReverseAxesWalker.java 2001/06/12 19:16:21 1.7
+++ ReverseAxesWalker.java 2001/07/28 00:45:05 1.8
@@ -108,6 +108,8 @@
*/
protected int getNextNode()
{
+ if (m_foundLast)
+ return DTM.NULL;
int next = m_iterator.next();
@@ -115,7 +117,7 @@
m_isFresh = false;
if (DTM.NULL == next)
- this.m_isDone = true;
+ this.m_foundLast = true;
return next;
}
1.10 +14 -0 xml-xalan/java/src/org/apache/xpath/objects/XNumber.java
Index: XNumber.java
===================================================================
RCS file: /home/cvs/xml-xalan/java/src/org/apache/xpath/objects/XNumber.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- XNumber.java 2001/06/12 19:16:52 1.9
+++ XNumber.java 2001/07/28 00:45:05 1.10
@@ -419,4 +419,18 @@
throw new org.apache.xml.utils.WrappedRuntimeException(te);
}
}
+
+ /**
+ * Tell if this expression returns a stable number that will not change
during
+ * iterations within the expression. This is used to determine if a
proximity
+ * position predicate can indicate that no more searching has to occur.
+ *
+ *
+ * @return true if the expression represents a stable number.
+ */
+ public boolean isStableNumber()
+ {
+ return true;
+ }
+
}
1.14 +14 -0
xml-xalan/java/src/org/apache/xpath/operations/Variable.java
Index: Variable.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xpath/operations/Variable.java,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -r1.13 -r1.14
--- Variable.java 2001/07/28 00:26:00 1.13
+++ Variable.java 2001/07/28 00:45:05 1.14
@@ -237,4 +237,18 @@
throw new
javax.xml.transform.TransformerException(XSLMessages.createXPATHMessage(XPATHErrorResources.ER_VAR_NOT_RESOLVABLE,
new Object[]{m_qname.toString()})); //"Variable not resolvable: "+m_qname);
}
}
+
+ /**
+ * Tell if this expression returns a stable number that will not change
during
+ * iterations within the expression. This is used to determine if a
proximity
+ * position predicate can indicate that no more searching has to occur.
+ *
+ *
+ * @return true if the expression represents a stable number.
+ */
+ public boolean isStableNumber()
+ {
+ return true;
+ }
+
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]