needle
needle copied to clipboard
Use String#indexOf to find literals
When searching for a literal in a string, we'd prefer to use String#indexOf, as it's implemented using Hotspot intrinsics, which ought to outperform anything we can write by hand.
Sadly, String#indexOf supports searching through the entire string, or searching through a suffix of the String, but does not seem to support searching from indices [m,n] where 0 < m < n < stringlength. This means that we can sometimes use these methods, but not always. Additionally, we may have to have separate code paths or runtime checks whether we're searching in a substring or the entire string.