sboag 01/07/31 09:29:51
Modified: java/src/org/apache/xpath/objects XNodeSet.java XObject.java
java/src/org/apache/xpath/patterns StepPattern.java
Log:
Detach expressions in match patterns. Also, defined
numWithSideEffects and boolWithSideEffects (for lack of
better names) that will increment the iterator, and call these
for predicates. The combination of these results in about an
18% performance improvement for decoy.xsl.
Credits to Mukund Raghavachari/Watson/[EMAIL PROTECTED]
Revision Changes Path
1.18 +28 -0 xml-xalan/java/src/org/apache/xpath/objects/XNodeSet.java
Index: XNodeSet.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xpath/objects/XNodeSet.java,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -r1.17 -r1.18
--- XNodeSet.java 2001/07/17 18:18:01 1.17
+++ XNodeSet.java 2001/07/31 16:29:51 1.18
@@ -173,6 +173,22 @@
return (node != DTM.NULL) ? getNumberFromNode(node) : Double.NaN;
}
+
+ /**
+ * Cast result object to a number, but allow side effects, such as the
+ * incrementing of an iterator.
+ *
+ * @return numeric value of the string conversion from the
+ * next node in the NodeSetDTM, or NAN if no node was found
+ */
+ public double numWithSideEffects()
+ {
+ DTMIterator nl = iterRaw();
+ int node = nl.nextNode();
+
+ return (node != DTM.NULL) ? getNumberFromNode(node) : Double.NaN;
+ }
+
/**
* Cast result object to a boolean.
@@ -183,6 +199,18 @@
{
return (iter().nextNode() != DTM.NULL);
}
+
+ /**
+ * Cast result object to a boolean, but allow side effects, such as the
+ * incrementing of an iterator.
+ *
+ * @return True if there is a next node in the nodeset
+ */
+ public boolean boolWithSideEffects()
+ {
+ return (iterRaw().nextNode() != DTM.NULL);
+ }
+
/**
* Get the string conversion from a single node.
1.14 +24 -0 xml-xalan/java/src/org/apache/xpath/objects/XObject.java
Index: XObject.java
===================================================================
RCS file: /home/cvs/xml-xalan/java/src/org/apache/xpath/objects/XObject.java,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -r1.13 -r1.14
--- XObject.java 2001/06/15 21:18:37 1.13
+++ XObject.java 2001/07/31 16:29:51 1.14
@@ -290,6 +290,18 @@
return 0.0;
}
+
+ /**
+ * Cast result object to a number, but allow side effects, such as the
+ * incrementing of an iterator.
+ *
+ * @return numeric value of the string conversion from the
+ * next node in the NodeSetDTM, or NAN if no node was found
+ */
+ public double numWithSideEffects() throws
javax.xml.transform.TransformerException
+ {
+ return num();
+ }
/**
* Cast result object to a boolean. Always issues an error.
@@ -306,6 +318,18 @@
return false;
}
+
+ /**
+ * Cast result object to a boolean, but allow side effects, such as the
+ * incrementing of an iterator.
+ *
+ * @return True if there is a next node in the nodeset
+ */
+ public boolean boolWithSideEffects() throws
javax.xml.transform.TransformerException
+ {
+ return bool();
+ }
+
/**
* Cast result object to a string.
1.22 +54 -32
xml-xalan/java/src/org/apache/xpath/patterns/StepPattern.java
Index: StepPattern.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xpath/patterns/StepPattern.java,v
retrieving revision 1.21
retrieving revision 1.22
diff -u -r1.21 -r1.22
--- StepPattern.java 2001/07/27 17:42:41 1.21
+++ StepPattern.java 2001/07/31 16:29:51 1.22
@@ -479,15 +479,22 @@
{
XObject pred = m_predicates[i].execute(xctxt);
- if (XObject.CLASS_NUMBER == pred.getType())
+ try
{
- throw new Error("Why: Should never have been called");
+ if (XObject.CLASS_NUMBER == pred.getType())
+ {
+ throw new Error("Why: Should never have been called");
+ }
+ else if (!pred.boolWithSideEffects())
+ {
+ pass = false;
+
+ break;
+ }
}
- else if (!pred.bool())
+ finally
{
- pass = false;
-
- break;
+ pred.detach();
}
}
}
@@ -561,20 +568,27 @@
{
XObject pred = m_predicates[i].execute(xctxt);
- if (XObject.CLASS_NUMBER == pred.getType())
+ try
{
- if ((pos + 1) != (int) pred.num())
+ if (XObject.CLASS_NUMBER == pred.getType())
{
+ if ((pos + 1) != (int) pred.numWithSideEffects())
+ {
+ pass = false;
+
+ break;
+ }
+ }
+ else if (!pred.boolWithSideEffects())
+ {
pass = false;
-
+
break;
}
}
- else if (!pred.bool())
+ finally
{
- pass = false;
-
- break;
+ pred.detach();
}
}
}
@@ -762,33 +776,41 @@
{
XObject pred = m_predicates[i].execute(xctxt);
- if (XObject.CLASS_NUMBER == pred.getType())
+ try
{
- int pos = (int) pred.num();
-
- if (positionAlreadySeen)
+ if (XObject.CLASS_NUMBER == pred.getType())
{
- result = (pos == 1);
-
- break;
- }
- else
- {
- positionAlreadySeen = true;
-
- if (!checkProximityPosition(xctxt, i, dtm, currentNode, pos))
+ int pos = (int) pred.num();
+
+ if (positionAlreadySeen)
{
- result = false;
-
+ result = (pos == 1);
+
break;
}
+ else
+ {
+ positionAlreadySeen = true;
+
+ if (!checkProximityPosition(xctxt, i, dtm, currentNode, pos))
+ {
+ result = false;
+
+ break;
+ }
+ }
+
}
+ else if (!pred.boolWithSideEffects())
+ {
+ result = false;
+
+ break;
+ }
}
- else if (!pred.bool())
+ finally
{
- result = false;
-
- break;
+ pred.detach();
}
}
finally
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]