changeset 3191:ef0db530c341

Removed some expensive XPath usage. flys-artifacts/trunk@4807 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Wed, 27 Jun 2012 09:16:28 +0000
parents 49fe2ed03c12
children cd309f8597f6
files flys-artifacts/ChangeLog flys-artifacts/src/main/java/de/intevation/flys/collections/AttributeParser.java
diffstat 2 files changed, 31 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog	Tue Jun 26 17:20:31 2012 +0000
+++ b/flys-artifacts/ChangeLog	Wed Jun 27 09:16:28 2012 +0000
@@ -1,3 +1,13 @@
+2012-06-26	Sascha L. Teichmann	<sascha.teichmann@intevation.de>
+
+	* src/main/java/de/intevation/flys/collections/AttributeParser.java:
+	  Removed some expensive XPath usage. Some quick profiling 
+	  showed that up to 7% of our code (excluding Hibernate, H2, Restlet, etc.)
+	  were spend in these XPaths. A lot of time
+	  
+	  !!! Please, please, dear fellow programmers do not use XPath for fetching
+	  !!! trivial things that are easily accessible via DOM, too!
+
 2012-06-26	Sascha L. Teichmann	<sascha.teichmann@intevation.de>
 
 	* src/main/java/de/intevation/flys/artifacts/model/sq/Outlier.java,
--- a/flys-artifacts/src/main/java/de/intevation/flys/collections/AttributeParser.java	Tue Jun 26 17:20:31 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/collections/AttributeParser.java	Wed Jun 27 09:16:28 2012 +0000
@@ -120,12 +120,21 @@
         parseItems(out, name);
     }
 
+    private static final Node getChild(Element element, String name) {
+        NodeList children = element.getChildNodes();
+        for (int i = 0, N = children.getLength(); i < N; ++i) {
+            Node child = children.item(i);
+            if (child.getNodeType() == Node.ELEMENT_NODE
+            && child.getLocalName().equals(name)) {
+                return child;
+            }
+        }
+        return null;
+    }
+
 
     protected void parseSettings(Node out, String outname) {
-        Node settingsNode = (Node) XMLUtils.xpath(
-            out, "settings",
-            XPathConstants.NODE,
-            null);
+        Node settingsNode = getChild((Element)out, "settings");
 
         if (settingsNode == null) {
             logger.debug("No Settings found for Output '" + outname + "'");
@@ -138,21 +147,20 @@
 
 
     protected void parseItems(Node out, String outname) {
-        NodeList themes = (NodeList) XMLUtils.xpath(
-            out, "art:facet",
-            XPathConstants.NODESET,
-            ArtifactNamespaceContext.INSTANCE);
+        String uri = ArtifactNamespaceContext.NAMESPACE_URI;
+        Element element = (Element)out;
 
-        int num = themes != null ? themes.getLength() : 0;
+        NodeList themes = element.getElementsByTagNameNS(uri, "facet");
+
+        int num = themes.getLength();
 
         logger.debug("Output has " + num + " themes.");
 
-        String uri = ArtifactNamespaceContext.NAMESPACE_URI;
-
         for (int i = 0; i < num; i++) {
             Element theme = (Element) themes.item(i);
-
-            attribute.addFacet(outname, new ManagedDomFacet(theme));
+            if (theme.getParentNode() == out) {
+                attribute.addFacet(outname, new ManagedDomFacet(theme));
+            }
         }
     }
 }

http://dive4elements.wald.intevation.org