[jdom-interest] Reference comparisons in SAXHandler.startElement

Rosen, Alex arosen at silverstream.com
Tue Mar 13 12:14:37 PST 2001


Good point. On the other hand, when the strings don't match, String.equals() is
usually going to discover this by examining just the first character or two (in
the most common cases). Not as fast as ==, but it won't have to check every
single character. It just doesn't seem like this optimization is worth the bugs
it'll introduce.

Alex Rosen
SilverStream Software

> -----Original Message-----
> From: Jason Hunter [mailto:jhunter at collab.net]
> Sent: Tuesday, March 13, 2001 1:36 PM
> To: Rosen, Alex
> Cc: jdom-interest at jdom.org
> Subject: Re: [jdom-interest] Reference comparisons in
> SAXHandler.startElement
>
>
> "Rosen, Alex" wrote:
> >
> > The first thing that String.equals() does is to see if the
> two strings are ==
> > and return true if so. So why not just use .equals()? The
> cost of the extra
> > method call will certainly be lost in the noise.
>
> Your proposal would allow a comparison to "succeed fast" but "fail
> slowly".  That's only good if you expect success.  In SAX building it's
> expected the names won't match, and thus it's faster to have the ==
> check so you can fail quickly also.
>
> -jh-



More information about the jdom-interest mailing list