mirror of
https://github.com/openjdk/jdk.git
synced 2026-01-28 12:09:14 +00:00
remove unsafe
This commit is contained in:
parent
c58aa70718
commit
cebefd7b89
@ -143,44 +143,11 @@ public final class DecimalDigits {
|
||||
* @return If both characters are digits, return (str[offset] - '0') * 10 + (str[offset + 1] - '0'), otherwise return -1
|
||||
*/
|
||||
public static int digit2(byte[] str, int offset) {
|
||||
// Used by trusted callers. Assumes all necessary bounds checks have been done by the caller.
|
||||
/*
|
||||
Here we are doing a 2-Byte Vector operation on the short type.
|
||||
|
||||
x & 0xF0 != 0x30
|
||||
---------------
|
||||
0 0b0011_0000 & 0b1111_0000 = 0b0011_0000
|
||||
1 0b0011_0001 & 0b1111_0000 = 0b0011_0000
|
||||
2 0b0011_0010 & 0b1111_0000 = 0b0011_0000
|
||||
3 0b0011_0011 & 0b1111_0000 = 0b0011_0000
|
||||
4 0b0011_0100 & 0b1111_0000 = 0b0011_0000
|
||||
5 0b0011_0101 & 0b1111_0000 = 0b0011_0000
|
||||
6 0b0011_0110 & 0b1111_0000 = 0b0011_0000
|
||||
7 0b0011_0111 & 0b1111_0000 = 0b0011_0000
|
||||
8 0b0011_1000 & 0b1111_0000 = 0b0011_0000
|
||||
9 0b0011_1001 & 0b1111_0000 = 0b0011_0000
|
||||
|
||||
(((d = x & 0x0F) + 0x06) & 0xF0) != 0
|
||||
---------------
|
||||
0 ((0b0011_0000) & 0b0000_1111 + 0b0110_0000) & 0b1111_0000 = 0b0110_0000
|
||||
1 ((0b0011_0001) & 0b0000_1111 + 0b0110_0000) & 0b1111_0000 = 0b0110_0000
|
||||
2 ((0b0011_0010) & 0b0000_1111 + 0b0110_0000) & 0b1111_0000 = 0b0110_0000
|
||||
3 ((0b0011_0011) & 0b0000_1111 + 0b0110_0000) & 0b1111_0000 = 0b0110_0000
|
||||
4 ((0b0011_0100) & 0b0000_1111 + 0b0110_0000) & 0b1111_0000 = 0b0110_0000
|
||||
5 ((0b0011_0101) & 0b0000_1111 + 0b0110_0000) & 0b1111_0000 = 0b0110_0000
|
||||
6 ((0b0011_0110) & 0b0000_1111 + 0b0110_0000) & 0b1111_0000 = 0b0110_0000
|
||||
7 ((0b0011_0111) & 0b0000_1111 + 0b0110_0000) & 0b1111_0000 = 0b0110_0000
|
||||
8 ((0b0011_1000) & 0b0000_1111 + 0b0110_0000) & 0b1111_0000 = 0b0110_0000
|
||||
9 ((0b0011_1001) & 0b0000_1111 + 0b0110_0000) & 0b1111_0000 = 0b0110_0000
|
||||
*/
|
||||
int d;
|
||||
short x = UNSAFE.getShortUnaligned(str, Unsafe.ARRAY_BYTE_BASE_OFFSET + offset, false);
|
||||
if ((((x & 0xF0F0) - 0x3030)
|
||||
| (((d = x & 0x0F0F) + 0x0606) & 0xF0F0)) != 0
|
||||
) {
|
||||
return -1;
|
||||
byte c0 = str[offset], c1 = str[offset + 1];
|
||||
if (c0 >= '0' && c0 <= '9' && c1 >= '0' && c1 <= '9') {
|
||||
return c0 * 10 + c1 - ('0' * 10 + '0');
|
||||
}
|
||||
return (d & 0xF) * 10 + (d >> 8);
|
||||
return -1;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user