More message about optimization: In my personal crusade against futile XPath I have found a new easy target for time reductions ;)

I have just change _cxpathAPI.selectNodeList(rootNode, Canonicalizer.XPATH_C14N_WITH_COMMENTS_SINGLE_NODE); that his main purpose is select all nodes in the document with a DOM one that does the same thing XMLUtils.getSetWithComments (Horrible name if some has a better one please feel free). And try not to create a CachedXPath object that are horrible waste if not used.

All in All running the test goes from 56.6 seconds to 50.3 secondes (10% speed-up) not bad. I think you'll see more speed-up you don't use xpath in your signatures.

p.s. What's the differences XPATH_C14N_WITH_COMMENTS_SINGLE_NODE & XPATH_C14N_WITH_COMMENTS, and why it matters?

Index: org/apache/xml/security/signature/XMLSignatureInput.java
===================================================================
RCS file: /home/cvspublic/xml-security/src/org/apache/xml/security/signature/XMLSignatureInput.java,v
retrieving revision 1.25
diff -u -r1.25 XMLSignatureInput.java
--- org/apache/xml/security/signature/XMLSignatureInput.java 17 Apr 2004 04:27:36 -0000 1.25
+++ org/apache/xml/security/signature/XMLSignatureInput.java 20 Apr 2004 19:33:01 -0000
@@ -26,6 +26,7 @@
import java.io.StringWriter;
import java.io.UnsupportedEncodingException;
import java.io.Writer;
+import java.util.HashSet;
import java.util.Set;


import javax.xml.parsers.DocumentBuilder;
@@ -144,14 +145,14 @@
      this._cxpathAPI = usedXPathAPI;

      // get the Document and make all namespace nodes visible in DOM space
-      Document doc = XMLUtils.getOwnerDocument(rootNode);
+      //Document doc = XMLUtils.getOwnerDocument(rootNode);

-      XMLUtils.circumventBug2650(doc);
+      //XMLUtils.circumventBug2650(doc);

- NodeList result = this._cxpathAPI.selectNodeList(rootNode,
- Canonicalizer.XPATH_C14N_WITH_COMMENTS_SINGLE_NODE);
+ // NodeList result = this._cxpathAPI.selectNodeList(rootNode,
+ // Canonicalizer.XPATH_C14N_WITH_COMMENTS_SINGLE_NODE);


- this._inputNodeSet = XMLUtils.convertNodelistToSet(result);
+ this._inputNodeSet = XMLUtils.getSetWithComments(rootNode,new HashSet());
}


   /**
@@ -162,7 +163,7 @@
    * @throws TransformerException
    */
   public XMLSignatureInput(Node rootNode) throws TransformerException {
-      this(rootNode, new CachedXPathAPI());
+      this(rootNode, null /*new CachedXPathAPI()*/);
   }

   /**
@@ -232,27 +233,23 @@
         DocumentBuilder db = dfactory.newDocumentBuilder();

// select all nodes, also the comments.
- if (this._cxpathAPI==null) {
- this._cxpathAPI=new CachedXPathAPI();
- }
-
+ try {
db.setErrorHandler(new org.apache.xml.security.utils
.IgnoreAllErrorHandler());


Document doc = db.parse(this.getOctetStream());

-            XMLUtils.circumventBug2650(doc);
+            //XMLUtils.circumventBug2650(doc);

- NodeList nodeList =
+ /*NodeList nodeList =
this._cxpathAPI
.selectNodeList(doc,
Canonicalizer
.XPATH_C14N_WITH_COMMENTS_SINGLE_NODE);
-
- return XMLUtils.convertNodelistToSet(nodeList);
- } catch (TransformerException ex) {
- throw new CanonicalizationException("generic.EmptyMessage", ex);
+ */
+ XMLUtils.circumventBug2650(doc);
+ return XMLUtils.getSetWithComments(doc.getDocumentElement(), new HashSet()); /*convertNodelistToSet(nodeList);*/ } catch (SAXException ex) {


// if a not-wellformed nodeset exists, put a container around it...
Index: org/apache/xml/security/transforms/implementations/TransformEnvelopedSignature.java
===================================================================
RCS file: /home/cvspublic/xml-security/src/org/apache/xml/security/transforms/implementations/TransformEnvelopedSignature.java,v
retrieving revision 1.9
diff -u -r1.9 TransformEnvelopedSignature.java
--- org/apache/xml/security/transforms/implementations/TransformEnvelopedSignature.java 8 Feb 2004 06:11:35 -0000 1.9
+++ org/apache/xml/security/transforms/implementations/TransformEnvelopedSignature.java 20 Apr 2004 19:33:01 -0000
@@ -152,7 +152,7 @@
}


         XMLSignatureInput result = new XMLSignatureInput(resultSet,
-                                       input.getCachedXPathAPI());
+                                       null/*input.getCachedXPathAPI()*/);

return result;
} catch (IOException ex) {
Index: org/apache/xml/security/utils/XMLUtils.java
===================================================================
RCS file: /home/cvspublic/xml-security/src/org/apache/xml/security/utils/XMLUtils.java,v
retrieving revision 1.35
diff -u -r1.35 XMLUtils.java
--- org/apache/xml/security/utils/XMLUtils.java 8 Feb 2004 06:11:51 -0000 1.35
+++ org/apache/xml/security/utils/XMLUtils.java 20 Apr 2004 19:33:04 -0000
@@ -66,6 +66,28 @@
// we don't allow instantiation
}


+ public static Set getSetWithComments(Node rootNode,Set result) {
+ //Set result = new HashSet(); + switch (rootNode.getNodeType()) {
+ case Node.ELEMENT_NODE:
+ result.add(rootNode);
+ NamedNodeMap nl = ((Element)rootNode).getAttributes();
+ for (int i=0;i<nl.getLength();i++) {
+ result.add(nl.item(i));
+ }
+ Node r=rootNode.getFirstChild();
+ if (r==null) {
+ break;
+ }
+ do {
+ getSetWithComments(r,result);
+ } while ((r=r.getNextSibling())!=null);
+ break;
+ default:
+ result.add(rootNode);
+ }
+ return result;
+ }
/**
* Method getXalanVersion
*




Reply via email to