On Thu, 11 Sep 2025 11:56:30 GMT, Claes Redestad <[email protected]> wrote:

>> I had thought of these micro optimizations, but I thought we preferred 
>> clarity unless performance was proven to be an issue. I see 
>> contains("&lt;single-char&gt;") in other code - should we be changing that?
>
> I think replacing `startsWith(String)` with `indexOf(char)` is dubious, since 
> the latter is O(n) and the former O(1) 
> 
> If you _really_ need to squeeze out everything on startup then `(x.length() > 
> 0 && x.charAt(0) == '/')` is slightly faster in the interpreter (the 
> difference more or less disappears after JIT compilation). I'd keep using 
> `startsWith("/")`.

(Yes, `x.lastIndexOf('/', 0) == 0` is even faster for the interpreter, but 
let's keep it civil in these trying times.)

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/27203#discussion_r2340467282

Reply via email to