Hi Henning,

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

> "James Carman" <[EMAIL PROTECTED]> 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: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to