[Biojava-l] Re: unexpected behavior in StAX, StringElementHandlerBase

Christopher Pickslay chrispix@bigfoot.com
Tue, 18 Sep 2001 22:11:56 -0700


> > > > All of the StAXContentHandlerBase implementations appear to share this
> > > problem. They each contain a StringBuffer field that is initialized along
> > > with the class, rather than in startElement(). So not only will they 
> cause
> > > this behavior with sequential elements, but it means a
> > > StAXContentHandlerBase instance cannot be re-used. I'd recommend
> > > initializing the StringBuffer in startElement(), as that would be the
> > > expected behavior.
> > > is it better to re-initialize the StringBuffer, or call > 
> sb.delete(0,sb.length()) after calling setXValue(String)?
> > > I don't have a good profiling tool, so I'm just guessing here...
>
>I'd presume that sb.setLength(0) is fastest. But I doubt there's much 
>difference really...

Running a quick test, the speed difference appears to be negligible, with 
setLength(0) coming in slightly faster. In any case, that's probably a 
better design than re-initializing, as it doesn't proliferate empty 
instances to be garbage collected.

Christopher