# HG changeset patch # User Sascha L. Teichmann # Date 1340788588 0 # Node ID ef0db530c3419fd3b41a7de9405c0f8aae3ec354 # Parent 49fe2ed03c12a749f91eecfa9cac74195507fdf0 Removed some expensive XPath usage. flys-artifacts/trunk@4807 c6561f87-3c4e-4783-a992-168aeb5c3f6f diff -r 49fe2ed03c12 -r ef0db530c341 flys-artifacts/ChangeLog --- 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 + + * 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 * src/main/java/de/intevation/flys/artifacts/model/sq/Outlier.java, diff -r 49fe2ed03c12 -r ef0db530c341 flys-artifacts/src/main/java/de/intevation/flys/collections/AttributeParser.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)); + } } } }