sboag 01/06/22 20:54:31
Modified: java/src/org/apache/xpath/axes FilterExprWalker.java
LocPathIterator.java UnionPathIterator.java
WalkingIteratorSorted.java
Log:
Address bug reported by Norm Walsh (Bugzilla Bug 2275 Xalan doesn't fire the
right templates).
Regression test for this bug is new position80.
The union pattern wasn't firing correctly. This was caused by an
optimization that occured where we tried not to clone the iterators
in the UnionIterator clone function.
There were also some problems with gettting the last node count.
Fixing this uncovered another problem with a previous fix to
LocationPathIterator where the cachedNode list wasn't being
created if it was already non-null. This was fixed by making sure
the list is reset (but not reallocated) in the WalkingIteratorSorted.
Revision Changes Path
1.18 +16 -41
xml-xalan/java/src/org/apache/xpath/axes/FilterExprWalker.java
Index: FilterExprWalker.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xpath/axes/FilterExprWalker.java,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -r1.17 -r1.18
--- FilterExprWalker.java 2001/06/21 01:55:17 1.17
+++ FilterExprWalker.java 2001/06/23 03:54:30 1.18
@@ -161,7 +161,6 @@
else
m_nodeSet = m_expr.asIterator(xctxt, root);
- m_peek = DTM.NULL;
}
catch (javax.xml.transform.TransformerException se)
{
@@ -237,30 +236,25 @@
public int getNextNode()
{
- int next;
-
- if (DTM.NULL != m_peek)
- {
- next = m_peek;
- m_peek = DTM.NULL;
- }
+ if (null != m_nodeSet)
+ return m_nodeSet.nextNode();
else
- {
- if (null != m_nodeSet)
- {
- int current = this.getCurrentNode();
-
- next = m_nodeSet.nextNode();
- }
- else
- next = DTM.NULL;
- }
-
- // int current = setCurrentIfNotNull(next);
- // System.out.println("Returning: "+this);
- return next;
+ return DTM.NULL;
}
+ /**
+ * Get the index of the last node that can be itterated to.
+ *
+ *
+ * @param xctxt XPath runtime context.
+ *
+ * @return the index of the last node that can be itterated to.
+ */
+ public int getLastPos(XPathContext xctxt)
+ {
+ return m_nodeSet.getLength();
+ }
+
/** The contained expression. Should be non-null.
* @serial */
private Expression m_expr;
@@ -268,25 +262,6 @@
/** The result of executing m_expr. Needs to be deep cloned on clone op.
*/
transient private DTMIterator m_nodeSet;
- /** I think this is always null right now. */
- transient private int m_peek = DTM.NULL;
-
- /**
- * Tell what's the maximum level this axes can descend to (which is
actually
- * impossible to predict with this walker?).
- *
- * @return always a level of 1 right now.
- */
- protected int getLevelMax()
- {
-
- // TODO: Oh, this is going to be a hell of a lot of fun...
- // return Short.MAX_VALUE;
- return 1; // bogus, will probably screw things up.
-
- // return m_lpi.getDOMHelper().getLevel(this.m_currentNode)+1;
- }
-
/**
* This function is used to fixup variables from QNames to stack frame
* indexes at stylesheet build time.
1.28 +16 -4
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.27
retrieving revision 1.28
diff -u -r1.27 -r1.28
--- LocPathIterator.java 2001/06/22 04:35:06 1.27
+++ LocPathIterator.java 2001/06/23 03:54:30 1.28
@@ -338,7 +338,7 @@
m_cdtm = xctxt.getDTM(context);
m_currentContextNode = context;
m_prefixResolver = xctxt.getNamespaceContext();
-
+
// m_lastFetched = DTM.NULL;
// m_currentContextNode = DTM.NULL;
// m_foundLast = false;
@@ -347,7 +347,7 @@
if (m_isTopLevel)
this.m_stackFrame = xctxt.getVarStack().getStackFrame();
-
+
reset();
}
@@ -396,7 +396,9 @@
if (b)
{
if(null == m_cachedNodes)
+ {
m_cachedNodes = new NodeSetDTM();
+ }
}
else
m_cachedNodes = null;
@@ -893,7 +895,15 @@
*/
public int getLastPos(XPathContext xctxt)
{
- int pos = getProximityPosition();
+ int savedPos;
+ if(null != m_cachedNodes)
+ savedPos = m_cachedNodes.getCurrentPos();
+ else
+ savedPos = -1;
+
+ int pos = (m_predicateIndex >= 0) ? getProximityPosition() :
+ ((null != m_cachedNodes) ? m_cachedNodes.getCurrentPos() :
m_next);
+
LocPathIterator clone;
try
@@ -918,8 +928,10 @@
{
pos++;
}
+
+ if(-1 != savedPos)
+ m_cachedNodes.setCurrentPos(savedPos);
- // System.out.println("pos: "+pos);
return pos;
}
1.20 +58 -13
xml-xalan/java/src/org/apache/xpath/axes/UnionPathIterator.java
Index: UnionPathIterator.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xpath/axes/UnionPathIterator.java,v
retrieving revision 1.19
retrieving revision 1.20
diff -u -r1.19 -r1.20
--- UnionPathIterator.java 2001/06/19 21:43:50 1.19
+++ UnionPathIterator.java 2001/06/23 03:54:30 1.20
@@ -432,15 +432,6 @@
UnionPathIterator clone = (UnionPathIterator) clone();
- // %OPT%
- // We have to make sure this is a deep clone. (yet another perf
issue...)
- int n = m_iterators.length;
-
- for (int i = 0; i < n; i++)
- {
- clone.m_iterators[i] = (DTMIterator)m_iterators[i].clone();
- }
-
clone.reset();
return clone;
@@ -464,7 +455,7 @@
for (int i = 0; i < n; i++)
{
- clone.m_iterators[i] = m_iterators[i];
+ clone.m_iterators[i] = (LocPathIterator)m_iterators[i].clone();
}
return clone;
@@ -739,11 +730,65 @@
*/
public int getLength()
{
+
+ // resetToCachedList();
+ if(m_last > 0)
+ return m_last;
+ else if(null == m_cachedNodes || !m_foundLast)
+ {
+ m_last = getLastPos(m_execContext);
+ }
+ else
+ {
+ m_last = m_cachedNodes.getLength();
+ }
+ return m_last;
+ }
+
+ /**
+ * Get the index of the last node that can be itterated to.
+ * This probably will need to be overridded by derived classes.
+ *
+ * @param xctxt XPath runtime context.
+ *
+ * @return the index of the last node that can be itterated to.
+ */
+ public int getLastPos(XPathContext xctxt)
+ {
+ int pos = m_next;
+ UnionPathIterator clone;
- // %REVIEW% ??
-// resetToCachedList();
+ int savedPos;
+ if(null != m_cachedNodes)
+ savedPos = m_cachedNodes.getCurrentPos();
+ else
+ savedPos = -1;
- return m_cachedNodes.getLength();
+ try
+ {
+ // %REVIEW% %OPT%
+ if(0 == pos && m_currentContextNode != DTM.NULL)
+ clone = (UnionPathIterator) cloneWithReset();
+ else
+ clone = (UnionPathIterator) clone();
+ }
+ catch (CloneNotSupportedException cnse)
+ {
+ return -1;
+ }
+
+ int next;
+ pos = clone.getCurrentPos();
+
+ while (DTM.NULL != (next = clone.nextNode()))
+ {
+ pos++;
+ }
+
+ if(-1 != savedPos)
+ m_cachedNodes.setCurrentPos(savedPos);
+
+ return pos;
}
/**
1.3 +7 -0
xml-xalan/java/src/org/apache/xpath/axes/WalkingIteratorSorted.java
Index: WalkingIteratorSorted.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xpath/axes/WalkingIteratorSorted.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- WalkingIteratorSorted.java 2001/06/12 19:16:24 1.2
+++ WalkingIteratorSorted.java 2001/06/23 03:54:30 1.3
@@ -53,6 +53,13 @@
super.setRoot(context, environment);
this.setShouldCacheNodes(true);
+
+ // This should really be done in the super's setRoot, but if I do that
+ // it becomes unhappy in the minitest... possibly something to do with
+ // the keyref iterator. -sb
+ m_cachedNodes.setLast(0);
+ m_cachedNodes.reset();
+ m_cachedNodes.RemoveAllNoClear();
setNextPosition(0);
m_firstWalker.setRoot(context);
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]