Merge
This commit is contained in:
commit
8d7fe09e10
@ -177,7 +177,7 @@ abstract class AbstractStringBuilder implements Appendable, CharSequence {
|
||||
return;
|
||||
}
|
||||
byte[] buf = StringUTF16.newBytesFor(value.length);
|
||||
StringLatin1.inflateSB(value, buf, 0, count);
|
||||
StringLatin1.inflate(value, 0, buf, 0, count);
|
||||
this.value = buf;
|
||||
this.coder = UTF16;
|
||||
}
|
||||
@ -414,9 +414,9 @@ abstract class AbstractStringBuilder implements Appendable, CharSequence {
|
||||
int n = srcEnd - srcBegin;
|
||||
checkRange(dstBegin, dstBegin + n, dst.length);
|
||||
if (isLatin1()) {
|
||||
StringLatin1.getCharsSB(value, srcBegin, srcEnd, dst, dstBegin);
|
||||
StringLatin1.getChars(value, srcBegin, srcEnd, dst, dstBegin);
|
||||
} else {
|
||||
StringUTF16.getCharsSB(value, srcBegin, srcEnd, dst, dstBegin);
|
||||
StringUTF16.getChars(value, srcBegin, srcEnd, dst, dstBegin);
|
||||
}
|
||||
}
|
||||
|
||||
@ -980,7 +980,7 @@ abstract class AbstractStringBuilder implements Appendable, CharSequence {
|
||||
if (isLatin1()) {
|
||||
return StringLatin1.newString(value, start, end - start);
|
||||
}
|
||||
return StringUTF16.newStringSB(value, start, end - start);
|
||||
return StringUTF16.newString(value, start, end - start);
|
||||
}
|
||||
|
||||
private void shift(int offset, int n) {
|
||||
@ -1576,7 +1576,7 @@ abstract class AbstractStringBuilder implements Appendable, CharSequence {
|
||||
if (this.coder == coder) {
|
||||
System.arraycopy(value, 0, dst, dstBegin << coder, count << coder);
|
||||
} else { // this.coder == LATIN && coder == UTF16
|
||||
StringLatin1.inflateSB(value, dst, dstBegin, count);
|
||||
StringLatin1.inflate(value, 0, dst, dstBegin, count);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1641,10 +1641,7 @@ abstract class AbstractStringBuilder implements Appendable, CharSequence {
|
||||
if (getCoder() != str.coder()) {
|
||||
inflate();
|
||||
}
|
||||
byte[] val = this.value;
|
||||
byte coder = this.coder;
|
||||
checkOffset(index + str.length(), val.length >> coder);
|
||||
str.getBytes(val, index, coder);
|
||||
str.getBytes(value, index, coder);
|
||||
}
|
||||
|
||||
private final void appendChars(char[] s, int off, int end) {
|
||||
|
@ -1720,7 +1720,6 @@ public final class String
|
||||
*/
|
||||
static int indexOf(byte[] src, byte srcCoder, int srcCount,
|
||||
String tgtStr, int fromIndex) {
|
||||
|
||||
byte[] tgt = tgtStr.value;
|
||||
byte tgtCoder = tgtStr.coder();
|
||||
int tgtCount = tgtStr.length();
|
||||
@ -3103,7 +3102,7 @@ public final class String
|
||||
* If {@code offset} is negative, {@code count} is negative,
|
||||
* or {@code offset} is greater than {@code length - count}
|
||||
*/
|
||||
private static void checkBoundsOffCount(int offset, int count, int length) {
|
||||
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);
|
||||
|
@ -413,7 +413,7 @@ public final class StringBuilder
|
||||
public String toString() {
|
||||
// Create a copy, don't share the array
|
||||
return isLatin1() ? StringLatin1.newString(value, 0, count)
|
||||
: StringUTF16.newStringSB(value, 0, count);
|
||||
: StringUTF16.newString(value, 0, count);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -36,6 +36,7 @@ import jdk.internal.HotSpotIntrinsicCandidate;
|
||||
import static java.lang.String.LATIN1;
|
||||
import static java.lang.String.UTF16;
|
||||
import static java.lang.String.checkOffset;
|
||||
import static java.lang.String.checkBoundsOffCount;
|
||||
|
||||
final class StringLatin1 {
|
||||
|
||||
@ -523,6 +524,8 @@ final class StringLatin1 {
|
||||
// inflatedCopy byte[] -> byte[]
|
||||
@HotSpotIntrinsicCandidate
|
||||
public static void inflate(byte[] src, int srcOff, byte[] dst, int dstOff, int len) {
|
||||
// We need a range check here because 'putChar' has no checks
|
||||
checkBoundsOffCount(dstOff, len, dst.length);
|
||||
for (int i = 0; i < len; i++) {
|
||||
StringUTF16.putChar(dst, dstOff++, src[srcOff++] & 0xff);
|
||||
}
|
||||
@ -584,17 +587,4 @@ final class StringLatin1 {
|
||||
return cs;
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////
|
||||
|
||||
public static void getCharsSB(byte[] val, int srcBegin, int srcEnd, char dst[], int dstBegin) {
|
||||
checkOffset(srcEnd, val.length);
|
||||
getChars(val, srcBegin, srcEnd, dst, dstBegin);
|
||||
}
|
||||
|
||||
public static void inflateSB(byte[] val, byte[] dst, int dstOff, int count) {
|
||||
checkOffset(count, val.length);
|
||||
checkOffset(dstOff + count, dst.length >> 1); // dst is utf16
|
||||
inflate(val, 0, dst, dstOff, count);
|
||||
}
|
||||
}
|
||||
|
@ -35,6 +35,7 @@ import static java.lang.String.UTF16;
|
||||
import static java.lang.String.LATIN1;
|
||||
import static java.lang.String.checkIndex;
|
||||
import static java.lang.String.checkOffset;
|
||||
import static java.lang.String.checkBoundsOffCount;
|
||||
|
||||
final class StringUTF16 {
|
||||
|
||||
@ -156,6 +157,8 @@ final class StringUTF16 {
|
||||
// compressedCopy byte[] -> byte[]
|
||||
@HotSpotIntrinsicCandidate
|
||||
public static int compress(byte[] src, int srcOff, byte[] dst, int dstOff, int len) {
|
||||
// We need a range check here because 'getChar' has no checks
|
||||
checkBoundsOffCount(srcOff, len, src.length);
|
||||
for (int i = 0; i < len; i++) {
|
||||
int c = getChar(src, srcOff++);
|
||||
if (c >>> 8 != 0) {
|
||||
@ -200,6 +203,8 @@ final class StringUTF16 {
|
||||
|
||||
@HotSpotIntrinsicCandidate
|
||||
public static void getChars(byte[] value, int srcBegin, int srcEnd, char dst[], int dstBegin) {
|
||||
// We need a range check here because 'getChar' has no checks
|
||||
checkBoundsOffCount(srcBegin, srcEnd - srcBegin, value.length);
|
||||
for (int i = srcBegin; i < srcEnd; i++) {
|
||||
dst[dstBegin++] = getChar(value, i);
|
||||
}
|
||||
@ -909,11 +914,6 @@ final class StringUTF16 {
|
||||
|
||||
////////////////////////////////////////////////////////////////
|
||||
|
||||
public static void getCharsSB(byte[] val, int srcBegin, int srcEnd, char dst[], int dstBegin) {
|
||||
checkOffset(srcEnd, val.length >> 1);
|
||||
getChars(val, srcBegin, srcEnd, dst, dstBegin);
|
||||
}
|
||||
|
||||
public static void putCharSB(byte[] val, int index, int c) {
|
||||
checkIndex(index, val.length >> 1);
|
||||
putChar(val, index, c);
|
||||
@ -946,11 +946,6 @@ final class StringUTF16 {
|
||||
return codePointCount(val, beginIndex, endIndex);
|
||||
}
|
||||
|
||||
public static String newStringSB(byte[] val, int index, int len) {
|
||||
checkOffset(index + len, val.length >> 1);
|
||||
return newString(val, index, len);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////
|
||||
|
||||
private static native boolean isBigEndian();
|
||||
|
Loading…
Reference in New Issue
Block a user