commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jörg Schaible <Joerg.Schai...@Elsag-Solutions.com>
Subject RE: Re: [lang] enhanced version of Class.forName
Date Tue, 06 Sep 2005 11:12:49 GMT
Hi Henning,

Henning P. Schmiedehausen wrote on Tuesday, September 06, 2005 9:30 AM:

> "James Carman" <james@carmanconsulting.com> writes:
> 
>> I would say that this is something that would be very useful.  We did
>> something similar in HiveMind.  I can imagine an implementation like:
> 
> I always wondered over the obsession with startsWith() and
> endsWith() in string-related commons code. These operations
> are hugely expensive, especially with long strings to check!
> 
> They are implemented using a loop and char compares. I very
> much prefer using charAt and length() for this; both are
> constant time operations.

[snip]

> 
>             while(namelen > 2
>                   && className.charAt(nameLen - 2) == '['
>                   && className.charAt(nameLen - 1) == ']')           
>                 { actualNameBuffer.append('[');
>                 nameLen -= 2;
>                 foundArray = true;
>             }

[snip]

Well, looking into the JDK source I see no real advantage of not using endsWith. x.endsWith("[]")
will exactly do 2 character compares (if the string matches), as well as your code above.
And it only has one bounds check, compared to 2 in your example (3 counting "nameLen>2").
endsWith has one indirect call more though. So why do you think, that endsWidth is not time
constant?

- Jörg
(who is not willing to accept myths just by word)

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message