xom-interest AT lists.ibiblio.org
Subject: XOM API for Processing XML with Java
List archive
Re: [XOM-interest] Element.getValue() optimization
- From: Elliotte Harold <elharo AT metalab.unc.edu>
- To: xom-interest <xom-interest AT lists.ibiblio.org>
- Subject: Re: [XOM-interest] Element.getValue() optimization
- Date: Mon, 23 May 2005 09:08:34 -0400
Wolfgang Hoschek wrote:
Here is a small optimization to Element.getValue(), with a fast path for cases where an element has one and only one Text child:
public final String getValue() {
// non-recursive algorithm avoids stack size limitations
if (this.getChildCount() == 0) return "";
Node current = this.getChild(0);
if (this.getChildCount() == 1 && current.isText()) return current.getValue(); // WH fast path
StringBuffer result = new StringBuffer(); // WH
int index = 0;
...
}
Sounds reasonable. I don't think this will hurt anything, and it's easy enough to do.
--
Elliotte Rusty Harold elharo AT metalab.unc.edu
XML in a Nutshell 3rd Edition Just Published!
http://www.cafeconleche.org/books/xian3/
http://www.amazon.com/exec/obidos/ISBN=0596007647/cafeaulaitA/ref=nosim
-
[XOM-interest] Element.getValue() optimization,
Wolfgang Hoschek, 05/23/2005
- Re: [XOM-interest] Element.getValue() optimization, Elliotte Harold, 05/23/2005
Archive powered by MHonArc 2.6.24.