mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-27 06:45:07 +02:00
8325169: Reduce String::indexOf overheads
Reviewed-by: rriggs, rgiulietti, mli
This commit is contained in:
parent
89e6a02e3b
commit
19e92201b4
4 changed files with 23 additions and 19 deletions
|
@ -2444,7 +2444,8 @@ public final class String
|
|||
* {@code -1} if the character does not occur.
|
||||
*/
|
||||
public int indexOf(int ch) {
|
||||
return indexOf(ch, 0);
|
||||
return isLatin1() ? StringLatin1.indexOf(value, ch, 0, value.length)
|
||||
: StringUTF16.indexOf(value, ch, 0, value.length >> 1);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -2500,8 +2501,9 @@ public final class String
|
|||
* {@code fromIndex} were larger than the string length, or were negative.
|
||||
*/
|
||||
public int indexOf(int ch, int fromIndex) {
|
||||
return isLatin1() ? StringLatin1.indexOf(value, ch, fromIndex, length())
|
||||
: StringUTF16.indexOf(value, ch, fromIndex, length());
|
||||
fromIndex = Math.max(fromIndex, 0);
|
||||
return isLatin1() ? StringLatin1.indexOf(value, ch, Math.min(fromIndex, value.length), value.length)
|
||||
: StringUTF16.indexOf(value, ch, Math.min(fromIndex, value.length >> 1), value.length >> 1);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue