String.contains(CharSequence) calls toString on argument

Aleksey Shipilev aleksey.shipilev at oracle.com
Fri Mar 20 12:28:10 UTC 2015


Hi,

On 03/20/2015 03:19 PM, Tomasz Kowalczewski wrote:
> Thank you, that is the kind of feedback I need!

Claes' feedback is spot on. While the change might help, be prepared
that performance research in the area covered by compiler intrinsics is
hard.

> I have also asked myself this question. Changing indexOf to accept
> CharSequence is the most intrusive move. Safest way is to just implement
> contains in a different way (taking code from indexOf) but adding
> indexOf(CharSequence) might provide more value for other use cases.

Dunno. I think we can fold special cases of indexOf(CharSequence) into
the intrinsic as well. I wonder if the change is "only" about
specializing indexOf(CharSequence) on the Java side to shortcut to
indexOf(String) and others, like String.contentEquals(CharSequence)
already does.

> According to Aleksey Shipilev (
> https://twitter.com/shipilev/status/560065173407662080)
> String.indexOf(String) compiles to single asm instruction. 

Yes, the image prefix search is compiled down to that. With large image,
you first search the prefix with vectorized insns, and the check the rest.

-Aleksey.




More information about the core-libs-dev mailing list