8325169: Reduce String::indexOf overheads

Reviewed-by: rriggs, rgiulietti, mli
This commit is contained in:
Claes Redestad 2024-02-05 16:30:05 +00:00
parent 89e6a02e3b
commit 19e92201b4
4 changed files with 23 additions and 19 deletions

View file

@ -604,12 +604,8 @@ final class StringUTF16 {
};
}
// Caller must ensure that from- and toIndex are within bounds
public static int indexOf(byte[] value, int ch, int fromIndex, int toIndex) {
fromIndex = Math.max(fromIndex, 0);
toIndex = Math.min(toIndex, value.length >> 1);
if (fromIndex >= toIndex) {
return -1;
}
if (ch < Character.MIN_SUPPLEMENTARY_CODE_POINT) {
// handle most cases here (ch is a BMP code point or a
// negative value (invalid code point))
@ -716,11 +712,6 @@ final class StringUTF16 {
@IntrinsicCandidate
private static int indexOfChar(byte[] value, int ch, int fromIndex, int max) {
checkBoundsBeginEnd(fromIndex, max, value);
return indexOfCharUnsafe(value, ch, fromIndex, max);
}
private static int indexOfCharUnsafe(byte[] value, int ch, int fromIndex, int max) {
for (int i = fromIndex; i < max; i++) {
if (getChar(value, i) == ch) {
return i;