src/java.base/share/classes/java/lang/StringUTF16.java
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File jdk Cdiff src/java.base/share/classes/java/lang/StringUTF16.java

src/java.base/share/classes/java/lang/StringUTF16.java

Print this page

        

*** 326,335 **** --- 326,355 ---- return indexOf(value, length(value), str, length(str), 0); } @HotSpotIntrinsicCandidate public static int indexOf(byte[] value, int valueCount, byte[] str, int strCount, int fromIndex) { + // Redundant. + // Callers: + // StringUTF16.indexOf(byte[] value, byte[] str): valid by construction + // return indexOf(value, length(value), str, length(str), 0); + // + // String.indexOf: + // StringUTF16.indexOf(src, srcCount, tgt, tgtCount, fromIndex); + // 0 <= tgtCount < tgtStr.length >> 1 + // byte[] tgt = tgtStr.value; + // int tgtCount = tgtStr.length(); + // + // 0 < fromIndex < srcCount + // + // 0 <= srcCount < src.length + // Covered by ABS.indexOf(): + // checkIndex(count, value.length >> coder); + // return String.indexOf(value, coder, count, str, fromIndex); + checkBoundsBeginEnd(fromIndex, valueCount, value.length >> 1); + checkBoundsBeginEnd(0, strCount, str.length >> 1); + char first = getChar(str, 0); int max = (valueCount - strCount); for (int i = fromIndex; i <= max; i++) { // Look for first character. if (getChar(value, i) != first) {
*** 363,372 **** --- 383,396 ---- return indexOfLatin1(value, length(value), str, str.length, 0); } @HotSpotIntrinsicCandidate public static int indexOfLatin1(byte[] src, int srcCount, byte[] tgt, int tgtCount, int fromIndex) { + // Redundant (similar to StringUTF16.indexOf). + checkBoundsBeginEnd(fromIndex, srcCount, src.length >> 1); + checkBoundsBeginEnd(0, tgtCount, tgt.length >> 1); + char first = (char)(tgt[0] & 0xff); int max = (srcCount - tgtCount); for (int i = fromIndex; i <= max; i++) { // Look for first character. if (getChar(src, i) != first) {
*** 388,397 **** --- 412,425 ---- return -1; } @HotSpotIntrinsicCandidate private static int indexOfChar(byte[] value, int ch, int fromIndex, int max) { + // Redundant: StringUTF16.indexOf (caller) does the checks + // max == value.length >> 1 + // 0 <= fromIndex <= max + checkBoundsBeginEnd(fromIndex, max, value.length >> 1); for (int i = fromIndex; i < max; i++) { if (getChar(value, i) == ch) { return i; } }
*** 403,412 **** --- 431,444 ---- */ private static int indexOfSupplementary(byte[] value, int ch, int fromIndex, int max) { if (Character.isValidCodePoint(ch)) { final char hi = Character.highSurrogate(ch); final char lo = Character.lowSurrogate(ch); + // Redundant: StringUTF16.indexOf (caller) does the checks + // max == value.length >> 1 + // 0 <= fromIndex <= max + checkBoundsBeginEnd(fromIndex, max, value.length >> 1); for (int i = fromIndex; i < max - 1; i++) { if (getChar(value, i) == hi && getChar(value, i + 1 ) == lo) { return i; } }
*** 418,429 **** --- 450,467 ---- public static int lastIndexOf(byte[] src, int srcCount, byte[] tgt, int tgtCount, int fromIndex) { int min = tgtCount - 1; int i = min + fromIndex; int strLastIndex = tgtCount - 1; + + // Redundant: covered by checks in String.lastIndexOf + checkIndex(strLastIndex, tgt.length >> 1); char strLastChar = getChar(tgt, strLastIndex); + // Redundant: not needed for String.lastIndexOf(), covered by ASB.lastIndexOf(). + checkIndex(i, src.length >> 1); + startSearchForLastChar: while (true) { while (i >= min && getChar(src, i) != strLastChar) { i--; }
src/java.base/share/classes/java/lang/StringUTF16.java
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File