mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-27 06:45:07 +02:00
8268698: Use Objects.check{Index,FromToIndex,FromIndexSize} for java.base
Reviewed-by: mchung, rriggs
This commit is contained in:
parent
a4e5f08fef
commit
afe957cd97
40 changed files with 186 additions and 284 deletions
|
@ -51,6 +51,7 @@ import java.util.stream.IntStream;
|
|||
import java.util.stream.Stream;
|
||||
import java.util.stream.StreamSupport;
|
||||
|
||||
import jdk.internal.util.Preconditions;
|
||||
import jdk.internal.vm.annotation.ForceInline;
|
||||
import jdk.internal.vm.annotation.IntrinsicCandidate;
|
||||
import jdk.internal.vm.annotation.Stable;
|
||||
|
@ -1571,9 +1572,7 @@ public final class String
|
|||
*/
|
||||
public int codePointBefore(int index) {
|
||||
int i = index - 1;
|
||||
if (i < 0 || i >= length()) {
|
||||
throw new StringIndexOutOfBoundsException(index);
|
||||
}
|
||||
checkIndex(i, length());
|
||||
if (isLatin1()) {
|
||||
return (value[i] & 0xff);
|
||||
}
|
||||
|
@ -1602,10 +1601,7 @@ public final class String
|
|||
* @since 1.5
|
||||
*/
|
||||
public int codePointCount(int beginIndex, int endIndex) {
|
||||
if (beginIndex < 0 || beginIndex > endIndex ||
|
||||
endIndex > length()) {
|
||||
throw new IndexOutOfBoundsException();
|
||||
}
|
||||
Objects.checkFromToIndex(beginIndex, endIndex, length());
|
||||
if (isLatin1()) {
|
||||
return endIndex - beginIndex;
|
||||
}
|
||||
|
@ -4556,10 +4552,7 @@ public final class String
|
|||
* negative or greater than or equal to {@code length}.
|
||||
*/
|
||||
static void checkIndex(int index, int length) {
|
||||
if (index < 0 || index >= length) {
|
||||
throw new StringIndexOutOfBoundsException("index " + index +
|
||||
", length " + length);
|
||||
}
|
||||
Preconditions.checkIndex(index, length, Preconditions.SIOOBE_FORMATTER);
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -4567,10 +4560,7 @@ public final class String
|
|||
* is negative or greater than {@code length}.
|
||||
*/
|
||||
static void checkOffset(int offset, int length) {
|
||||
if (offset < 0 || offset > length) {
|
||||
throw new StringIndexOutOfBoundsException("offset " + offset +
|
||||
", length " + length);
|
||||
}
|
||||
Preconditions.checkFromToIndex(offset, length, length, Preconditions.SIOOBE_FORMATTER);
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -4582,10 +4572,7 @@ public final class String
|
|||
* or {@code offset} is greater than {@code length - count}
|
||||
*/
|
||||
static void checkBoundsOffCount(int offset, int count, int length) {
|
||||
if (offset < 0 || count < 0 || offset > length - count) {
|
||||
throw new StringIndexOutOfBoundsException(
|
||||
"offset " + offset + ", count " + count + ", length " + length);
|
||||
}
|
||||
Preconditions.checkFromIndexSize(offset, count, length, Preconditions.SIOOBE_FORMATTER);
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -4597,10 +4584,7 @@ public final class String
|
|||
* {@code end}, or {@code end} is greater than {@code length}.
|
||||
*/
|
||||
static void checkBoundsBeginEnd(int begin, int end, int length) {
|
||||
if (begin < 0 || begin > end || end > length) {
|
||||
throw new StringIndexOutOfBoundsException(
|
||||
"begin " + begin + ", end " + end + ", length " + length);
|
||||
}
|
||||
Preconditions.checkFromToIndex(begin, end, length, Preconditions.SIOOBE_FORMATTER);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue