< prev index next >
src/java.base/share/classes/java/lang/StringUTF16.java
Print this page
@@ -118,11 +118,12 @@
@HotSpotIntrinsicCandidate
public static byte[] toBytes(char[] value, int off, int len) {
byte[] val = newBytesFor(len);
for (int i = 0; i < len; i++) {
- putChar(val, i, value[off++]);
+ putChar(val, i, value[off]);
+ off++;
}
return val;
}
public static byte[] compress(char[] val, int off, int len) {
@@ -143,30 +144,36 @@
// compressedCopy char[] -> byte[]
@HotSpotIntrinsicCandidate
private static int compress(char[] src, int srcOff, byte[] dst, int dstOff, int len) {
for (int i = 0; i < len; i++) {
- int c = src[srcOff++];
- if (c >>> 8 != 0) {
- return 0;
+ char c = src[srcOff];
+ if (c > 0xFF) {
+ len = 0;
+ break;
}
- dst[dstOff++] = (byte)c;
+ dst[dstOff] = (byte)c;
+ srcOff++;
+ dstOff++;
}
return len;
}
// 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) {
- return 0;
+ char c = getChar(src, srcOff);
+ if (c > 0xFF) {
+ len = 0;
+ break;
}
- dst[dstOff++] = (byte)c;
+ dst[dstOff] = (byte)c;
+ srcOff++;
+ dstOff++;
}
return len;
}
public static byte[] toBytes(int[] val, int index, int len) {
@@ -579,11 +586,11 @@
return toLowerCaseEx(str, value, result, i, locale, false);
}
bits |= cp;
putChar(result, i, cp);
}
- if (bits >>> 8 != 0) {
+ if (bits > 0xFF) {
return new String(result, UTF16);
} else {
return newString(result, 0, len);
}
}
@@ -676,11 +683,11 @@
return toUpperCaseEx(str, value, result, i, locale, false);
}
bits |= cp;
putChar(result, i, cp);
}
- if (bits >>> 8 != 0) {
+ if (bits > 0xFF) {
return new String(result, UTF16);
} else {
return newString(result, 0, len);
}
}
< prev index next >