xom-interest AT lists.ibiblio.org
Subject: XOM API for Processing XML with Java
List archive
[XOM-interest] Suggestion: transform recursion into iteration
- From: Wolfgang Hoschek <whoschek AT lbl.gov>
- To: xom-interest AT lists.ibiblio.org
- Subject: [XOM-interest] Suggestion: transform recursion into iteration
- Date: Fri, 26 Sep 2003 19:31:40 -0700
Not that it's a significant problem, but I'd transform recursions into iterations when doing so is obvious and clarity does not suffer:
nu.xom.Element
private static boolean isAncestor(Node parent, Node child) {
while (true) {
if (child == parent) return true;
if (parent == null) return false;
parent = parent.getParent();
}
}
instead of:
private static boolean isAncestor(Node parent, Node child) {
if (child == parent) return true;
if (parent == null) return false;
else return isAncestor(parent.getParent(), child);
}
(No need to hope that hotspot would some intelligent magic)
- [XOM-interest] Suggestion: transform recursion into iteration, Wolfgang Hoschek, 09/26/2003
Archive powered by MHonArc 2.6.24.