mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-27 14:54:52 +02:00
8339320: Optimize ClassFile Utf8EntryImpl#inflate
Reviewed-by: liach
This commit is contained in:
parent
fcc9c8d570
commit
a24525b67b
1 changed files with 58 additions and 55 deletions
|
@ -246,66 +246,69 @@ public abstract sealed class AbstractPoolEntry {
|
||||||
this.contentHash = hash;
|
this.contentHash = hash;
|
||||||
charLen = rawLen;
|
charLen = rawLen;
|
||||||
state = State.BYTE;
|
state = State.BYTE;
|
||||||
|
} else {
|
||||||
|
inflateNonAscii(singleBytes, hash);
|
||||||
}
|
}
|
||||||
else {
|
}
|
||||||
char[] chararr = new char[rawLen];
|
|
||||||
int chararr_count = singleBytes;
|
|
||||||
// Inflate prefix of bytes to characters
|
|
||||||
JLA.inflateBytesToChars(rawBytes, offset, chararr, 0, singleBytes);
|
|
||||||
|
|
||||||
int px = offset + singleBytes;
|
private void inflateNonAscii(int singleBytes, int hash) {
|
||||||
int utfend = offset + rawLen;
|
char[] chararr = new char[rawLen];
|
||||||
while (px < utfend) {
|
int chararr_count = singleBytes;
|
||||||
int c = (int) rawBytes[px] & 0xff;
|
// Inflate prefix of bytes to characters
|
||||||
switch (c >> 4) {
|
JLA.inflateBytesToChars(rawBytes, offset, chararr, 0, singleBytes);
|
||||||
case 0, 1, 2, 3, 4, 5, 6, 7: {
|
|
||||||
// 0xxx xxxx
|
int px = offset + singleBytes;
|
||||||
px++;
|
int utfend = offset + rawLen;
|
||||||
chararr[chararr_count++] = (char) c;
|
while (px < utfend) {
|
||||||
hash = 31 * hash + c;
|
int c = (int) rawBytes[px] & 0xff;
|
||||||
break;
|
switch (c >> 4) {
|
||||||
}
|
case 0, 1, 2, 3, 4, 5, 6, 7: {
|
||||||
case 12, 13: {
|
// 0xxx xxxx
|
||||||
// 110x xxxx 10xx xxxx
|
px++;
|
||||||
px += 2;
|
chararr[chararr_count++] = (char) c;
|
||||||
if (px > utfend) {
|
hash = 31 * hash + c;
|
||||||
throw malformedInput(utfend);
|
break;
|
||||||
}
|
|
||||||
int char2 = rawBytes[px - 1];
|
|
||||||
if ((char2 & 0xC0) != 0x80) {
|
|
||||||
throw malformedInput(px);
|
|
||||||
}
|
|
||||||
char v = (char) (((c & 0x1F) << 6) | (char2 & 0x3F));
|
|
||||||
chararr[chararr_count++] = v;
|
|
||||||
hash = 31 * hash + v;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case 14: {
|
|
||||||
// 1110 xxxx 10xx xxxx 10xx xxxx
|
|
||||||
px += 3;
|
|
||||||
if (px > utfend) {
|
|
||||||
throw malformedInput(utfend);
|
|
||||||
}
|
|
||||||
int char2 = rawBytes[px - 2];
|
|
||||||
int char3 = rawBytes[px - 1];
|
|
||||||
if (((char2 & 0xC0) != 0x80) || ((char3 & 0xC0) != 0x80)) {
|
|
||||||
throw malformedInput(px - 1);
|
|
||||||
}
|
|
||||||
char v = (char) (((c & 0x0F) << 12) | ((char2 & 0x3F) << 6) | (char3 & 0x3F));
|
|
||||||
chararr[chararr_count++] = v;
|
|
||||||
hash = 31 * hash + v;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
// 10xx xxxx, 1111 xxxx
|
|
||||||
throw malformedInput(px);
|
|
||||||
}
|
}
|
||||||
|
case 12, 13: {
|
||||||
|
// 110x xxxx 10xx xxxx
|
||||||
|
px += 2;
|
||||||
|
if (px > utfend) {
|
||||||
|
throw malformedInput(utfend);
|
||||||
|
}
|
||||||
|
int char2 = rawBytes[px - 1];
|
||||||
|
if ((char2 & 0xC0) != 0x80) {
|
||||||
|
throw malformedInput(px);
|
||||||
|
}
|
||||||
|
char v = (char) (((c & 0x1F) << 6) | (char2 & 0x3F));
|
||||||
|
chararr[chararr_count++] = v;
|
||||||
|
hash = 31 * hash + v;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case 14: {
|
||||||
|
// 1110 xxxx 10xx xxxx 10xx xxxx
|
||||||
|
px += 3;
|
||||||
|
if (px > utfend) {
|
||||||
|
throw malformedInput(utfend);
|
||||||
|
}
|
||||||
|
int char2 = rawBytes[px - 2];
|
||||||
|
int char3 = rawBytes[px - 1];
|
||||||
|
if (((char2 & 0xC0) != 0x80) || ((char3 & 0xC0) != 0x80)) {
|
||||||
|
throw malformedInput(px - 1);
|
||||||
|
}
|
||||||
|
char v = (char) (((c & 0x0F) << 12) | ((char2 & 0x3F) << 6) | (char3 & 0x3F));
|
||||||
|
chararr[chararr_count++] = v;
|
||||||
|
hash = 31 * hash + v;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
// 10xx xxxx, 1111 xxxx
|
||||||
|
throw malformedInput(px);
|
||||||
}
|
}
|
||||||
this.contentHash = hash;
|
|
||||||
charLen = chararr_count;
|
|
||||||
this.chars = chararr;
|
|
||||||
state = State.CHAR;
|
|
||||||
}
|
}
|
||||||
|
this.contentHash = hash;
|
||||||
|
charLen = chararr_count;
|
||||||
|
this.chars = chararr;
|
||||||
|
state = State.CHAR;
|
||||||
}
|
}
|
||||||
|
|
||||||
private ConstantPoolException malformedInput(int px) {
|
private ConstantPoolException malformedInput(int px) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue