digit2 not use Unsafe

This commit is contained in:
高铁 2025-09-15 09:31:52 +08:00
parent 9e99611f23
commit 3dcb294ae2
1 changed files with 2 additions and 16 deletions

View File

@ -8,10 +8,6 @@ import static com.alibaba.fastjson2.util.JDKUtils.*;
import static com.alibaba.fastjson2.util.JDKUtils.ARRAY_CHAR_BASE_OFFSET;
public class IOUtils {
static final int NULL_32 = BIG_ENDIAN ? 0x6e756c6c : 0x6c6c756e;
static final long NULL_64 = BIG_ENDIAN ? 0x6e0075006c006cL : 0x6c006c0075006eL;
static final int ALSE = BIG_ENDIAN ? 0x616c7365 : 0x65736c61;
static final long ALSE_64 = BIG_ENDIAN ? 0x61006c00730065L : 0x650073006c0061L;
static final int[] sizeTable = {9, 99, 999, 9999, 99999, 999999, 9999999, 99999999, 999999999, Integer.MAX_VALUE};
public static final int[] DIGITS_K = new int[1000];
private static final byte[] MIN_INT_BYTES = "-2147483648".getBytes();
@ -1268,10 +1264,7 @@ public class IOUtils {
}
public static int digit2(byte[] bytes, int off) {
short x = UNSAFE.getShort(bytes, ARRAY_BYTE_BASE_OFFSET + off);
if (BIG_ENDIAN) {
x = Short.reverseBytes(x);
}
int x = bytes[off] | (bytes[off + 1] << 8);
int d;
if ((((x & 0xF0F0) - 0x3030) | (((d = x & 0x0F0F) + 0x0606) & 0xF0F0)) != 0) {
return -1;
@ -1280,10 +1273,7 @@ public class IOUtils {
}
public static int digit2(char[] chars, int off) {
int x = UNSAFE.getInt(chars, ARRAY_CHAR_BASE_OFFSET + ((long) off << 1));
if (BIG_ENDIAN) {
x = Integer.reverseBytes(x);
}
int x = chars[off] | (chars[off + 1] << 16);
int d;
if ((((x & 0xFFF0FFF0) - 0x300030) | (((d = x & 0x0F000F) + 0x060006) & 0xF000F0)) != 0) {
return -1;
@ -1291,10 +1281,6 @@ public class IOUtils {
return (d & 0xF) * 10 + (d >> 16);
}
public static boolean isALSE(byte[] buf, int pos) {
return UNSAFE.getInt(buf, ARRAY_BYTE_BASE_OFFSET + pos) == ALSE;
}
public static int indexOfChar(byte[] value, int ch, int fromIndex, int max) {
for (int i = fromIndex; i < max; i++) {
if (value[i] == ch) {