Skip to Content.
Sympa Menu

xom-interest - [XOM-interest] Possible optimization for getValue()

xom-interest AT lists.ibiblio.org

Subject: XOM API for Processing XML with Java

List archive

Chronological Thread  
  • From: Elliotte Rusty Harold <elharo AT metalab.unc.edu>
  • To: Hallvard Trætteberg <hal AT idi.ntnu.no>, <xom-interest AT lists.ibiblio.org>
  • Cc:
  • Subject: [XOM-interest] Possible optimization for getValue()
  • Date: Thu, 25 Sep 2003 10:52:32 -0400

At 11:44 AM +0200 9/25/03, Hallvard Trætteberg wrote:


I also have a suggestion regarding Element's implementation of
Node.getValue(). It currently accumulates the childs' values in a
StringBuffer. In many cases there is only one child, and this could be
handled as a special case (for speed and reduced memory consumption), as
follows:

if (getChildCount() == 1) {
Node child = getChild(0);
if (child.isText() || child.isElement()) {
return child.getValue();
}
}
StringBuffer result = new StringBuffer();
for (int i = 0; i < getChildCount(); i++) {
...
}
return result.toString();
}

Of course, this complicates the code and may not increase the speed
much. However, the code is still fairly obvious, so why not?


Do you have any profiling data to indicate that this change is worthwhile?
--

Elliotte Rusty Harold
elharo AT metalab.unc.edu
Processing XML with Java (Addison-Wesley, 2002)
http://www.cafeconleche.org/books/xmljava
http://www.amazon.com/exec/obidos/ISBN%3D0201771861/cafeaulaitA




Archive powered by MHonArc 2.6.24.

Top of Page