Skip to Content.
Sympa Menu

xom-interest - Re: [XOM-interest] Possible ArrayList optimization

xom-interest AT lists.ibiblio.org

Subject: XOM API for Processing XML with Java

List archive

Chronological Thread  
  • From: dirk bergstrom <dirk AT juniper.net>
  • To: Elliotte Rusty Harold <elharo AT metalab.unc.edu>
  • Cc: xom-interest <xom-interest AT lists.ibiblio.org>
  • Subject: Re: [XOM-interest] Possible ArrayList optimization
  • Date: Mon, 12 May 2003 19:52:24 -0700

On 05/12/2003 07:14 PM, Elliotte Rusty Harold was heard to exclaim:
>>Is there any reason why an invocation of ArrayList.trimToSize (),
> I hadn't thought of that. How expensive is trimToSize()?

fairly cheap. about the same cost as extending the array. here's the source:

public void trimToSize() {
modCount++;
int oldCapacity = elementData.length;
if (size < oldCapacity) {
Object oldData[] = elementData;
elementData = new Object[size];
System.arraycopy(oldData, 0, elementData, 0, size);
}
}

> and you might be able to make that up by not having to
> constantly grow the arrays as you build the document. Just start them
> fairly large, and then chop it down when you're finished.

well, you probably don't want to start too big, since as you build a
document you'll have un-trimmed ArrayLists for many of the nodes.

--
Dirk Bergstrom dirk AT juniper.net
_____________________________________________
Juniper Networks Inc., Computer Geek
Tel: 408.745.3182 Fax: 408.745.8905





Archive powered by MHonArc 2.6.24.

Top of Page