< prev index next >

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

Print this page

        

*** 1,7 **** /* ! * Copyright (c) 1994, 2016, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this --- 1,7 ---- /* ! * Copyright (c) 1994, 2017, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this
*** 193,204 **** --- 193,207 ---- * that this static final field is not statically foldable, and to * avoid any possible circular dependency during vm initialization. */ static final boolean COMPACT_STRINGS; + static final boolean DEBUG_INTRINSICS; + static { COMPACT_STRINGS = true; + DEBUG_INTRINSICS = false; } /** * Class String is special cased within the Serialization Stream Protocol. *
*** 379,389 **** this.coder = LATIN1; } else { hibyte <<= 8; byte[] val = StringUTF16.newBytesFor(count); for (int i = 0; i < count; i++) { ! StringUTF16.putChar(val, i, hibyte | (ascii[offset++] & 0xff)); } this.value = val; this.coder = UTF16; } } --- 382,392 ---- this.coder = LATIN1; } else { hibyte <<= 8; byte[] val = StringUTF16.newBytesFor(count); for (int i = 0; i < count; i++) { ! StringUTF16.Trusted.putChar(val, i, hibyte | (ascii[offset++] & 0xff)); } this.value = val; this.coder = UTF16; } }
*** 1062,1076 **** } } else { if (!isLatin1()) { // utf16 str and latin1 abs can never be "equal" return false; } ! for (int i = 0; i < len; i++) { ! if ((char)(v1[i] & 0xff) != StringUTF16.getChar(v2, i)) { ! return false; ! } ! } } return true; } /** --- 1065,1075 ---- } } else { if (!isLatin1()) { // utf16 str and latin1 abs can never be "equal" return false; } ! return StringUTF16.contentEquals(v1, v2, len); } return true; } /**
*** 1118,1133 **** if ((val[i] & 0xff) != cs.charAt(i)) { return false; } } } else { ! for (int i = 0; i < n; i++) { ! if (StringUTF16.getChar(val, i) != cs.charAt(i)) { return false; } } - } return true; } /** * Compares this {@code String} to another {@code String}, ignoring case --- 1117,1130 ---- if ((val[i] & 0xff) != cs.charAt(i)) { return false; } } } else { ! if (!StringUTF16.contentEquals(val, cs, n)) { return false; } } return true; } /** * Compares this {@code String} to another {@code String}, ignoring case
*** 1332,1348 **** } } else { if (coder() == LATIN1) { while (len-- > 0) { if (StringLatin1.getChar(tv, toffset++) != ! StringUTF16.getChar(ov, ooffset++)) { return false; } } } else { while (len-- > 0) { ! if (StringUTF16.getChar(tv, toffset++) != StringLatin1.getChar(ov, ooffset++)) { return false; } } } --- 1329,1345 ---- } } else { if (coder() == LATIN1) { while (len-- > 0) { if (StringLatin1.getChar(tv, toffset++) != ! StringUTF16.Trusted.getChar(ov, ooffset++)) { return false; } } } else { while (len-- > 0) { ! if (StringUTF16.Trusted.getChar(tv, toffset++) != StringLatin1.getChar(ov, ooffset++)) { return false; } } }
*** 1460,1470 **** if (isLatin1()) { // && pcoder == UTF16 return false; } // coder == UTF16 && pcoder == LATIN1) while (po < pc) { ! if (StringUTF16.getChar(ta, toffset++) != (pa[po++] & 0xff)) { return false; } } } return true; --- 1457,1467 ---- if (isLatin1()) { // && pcoder == UTF16 return false; } // coder == UTF16 && pcoder == LATIN1) while (po < pc) { ! if (StringUTF16.Trusted.getChar(ta, toffset++) != (pa[po++] & 0xff)) { return false; } } } return true;
*** 1732,1741 **** --- 1729,1741 ---- fromIndex = 0; } if (tgtCount == 0) { return fromIndex; } + if (tgtCount > srcCount) { + return -1; + } if (srcCoder == tgtCoder) { return srcCoder == LATIN1 ? StringLatin1.indexOf(src, srcCount, tgt, tgtCount, fromIndex) : StringUTF16.indexOf(src, srcCount, tgt, tgtCount, fromIndex); }
*** 1805,1820 **** /* * Check arguments; return immediately where possible. For * consistency, don't check for null str. */ int rightIndex = srcCount - tgtCount; - if (fromIndex < 0) { - return -1; - } if (fromIndex > rightIndex) { fromIndex = rightIndex; } /* Empty string always matches. */ if (tgtCount == 0) { return fromIndex; } if (srcCoder == tgtCoder) { --- 1805,1820 ---- /* * Check arguments; return immediately where possible. For * consistency, don't check for null str. */ int rightIndex = srcCount - tgtCount; if (fromIndex > rightIndex) { fromIndex = rightIndex; } + if (fromIndex < 0) { + return -1; + } /* Empty string always matches. */ if (tgtCount == 0) { return fromIndex; } if (srcCoder == tgtCoder) {
*** 1824,1857 **** } if (srcCoder == LATIN1) { // && tgtCoder == UTF16 return -1; } // srcCoder == UTF16 && tgtCoder == LATIN1 ! int min = tgtCount - 1; ! int i = min + fromIndex; ! int strLastIndex = tgtCount - 1; ! ! char strLastChar = (char)(tgt[strLastIndex] & 0xff); ! startSearchForLastChar: ! while (true) { ! while (i >= min && StringUTF16.getChar(src, i) != strLastChar) { ! i--; ! } ! if (i < min) { ! return -1; ! } ! int j = i - 1; ! int start = j - strLastIndex; ! int k = strLastIndex - 1; ! while (j > start) { ! if (StringUTF16.getChar(src, j--) != (tgt[k--] & 0xff)) { ! i--; ! continue startSearchForLastChar; ! } ! } ! return start + 1; ! } } /** * Returns a string that is a substring of this string. The * substring begins with the character at the specified index and --- 1824,1834 ---- } if (srcCoder == LATIN1) { // && tgtCoder == UTF16 return -1; } // srcCoder == UTF16 && tgtCoder == LATIN1 ! return StringUTF16.lastIndexOfLatin1(src, srcCount, tgt, tgtCount, fromIndex); } /** * Returns a string that is a substring of this string. The * substring begins with the character at the specified index and
*** 3078,3088 **** * StringIndexOutOfBoundsException if {@code index} is * 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); } } /* * StringIndexOutOfBoundsException if {@code offset} --- 3055,3066 ---- * StringIndexOutOfBoundsException if {@code index} is * 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); } } /* * StringIndexOutOfBoundsException if {@code offset}
*** 3116,3126 **** * * @throws StringIndexOutOfBoundsException * If {@code begin} is negative, {@code begin} is greater than * {@code end}, or {@code end} is greater than {@code length}. */ ! private 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); } } --- 3094,3104 ---- * * @throws StringIndexOutOfBoundsException * If {@code begin} is negative, {@code begin} is greater than * {@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); } }
< prev index next >