While profilling again my program, I see that a lot of time is spend in Transforms.getLength, and it seems simple enought to not waste such time(I have the exact figures at work). So i try to see if rewriting it using only DOM instead of xpath can speed-up the things a little(I'm using the xpath that comes with the xalan that is store in the CVS perhaps other xpath implementation is faster).
I created a strip version of getLenght and I let them obtain 10000 times the number of transformations that are in this node:
<ds:Transforms xmlns:ds="http://www.w3.org/2000/09/xmldsig#" xmlns="http://www.w3.org/2000/09/xmldsig#">
<ds:Transform Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n-20010315"/> <ds:Transform><ds:Transform></ds:Transform></ds:Transform><Transform/>
<x:Transfrom xmlns:x="http://sss"/><ds:Transform/></ds:Transforms>
4=4
Xpath:21034ms
DOM:20ms
The node and the result are put above the speed-up is evident. Perhaps someone can use this patch.
p.s-sorry for my english.
Index: Transforms.java
===================================================================
RCS file: /home/cvspublic/xml-security/src/org/apache/xml/security/transforms/Transforms.java,v
retrieving revision 1.13
diff -u -r1.13 Transforms.java
--- Transforms.java 8 Feb 2004 06:11:35 -0000 1.13
+++ Transforms.java 14 Apr 2004 19:38:54 -0000
@@ -35,6 +35,7 @@
import org.w3c.dom.DOMException;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
+import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
@@ -247,18 +248,33 @@ */ public int getLength() throws TransformationException {
- try {
- Element nscontext = XMLUtils.createDSctx(this._doc, "ds",
+ + /*Element nscontext = XMLUtils.createDSctx(this._doc, "ds",
Constants.SignatureSpecNS);
NodeList transformElems =
XPathAPI.selectNodeList(this._constructionElement,
"./ds:Transform", nscontext);
- return transformElems.getLength();
- } catch (TransformerException ex) {
- throw new TransformationException("empty", ex);
+ return transformElems.getLength();*/
+ int size=0; + Node sibling= this._constructionElement.getFirstChild();
+ while (sibling!=null)
+ {
+ if ("Transform".equals(sibling.getLocalName())
+ && Constants.SignatureSpecNS.equals(sibling.getNamespaceURI())) {
+ size++;
+ }
+ sibling=sibling.getNextSibling();
+ }
+ if (size==0)
+ {
+ throw new TransformationException("empty");
+ }
+ return size;
+ + }
- }
+
/**
* Return the <it>i</it><sup>th</sup> <code>[EMAIL PROTECTED] Transform}</code>.