From 3dcb294ae2aa84200d7be5d399cda14aa0494f5a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=AB=98=E9=93=81?= Date: Mon, 15 Sep 2025 09:31:52 +0800 Subject: [PATCH] digit2 not use Unsafe --- .../com/alibaba/fastjson2/util/IOUtils.java | 18 ++---------------- 1 file changed, 2 insertions(+), 16 deletions(-) diff --git a/core/src/main/java/com/alibaba/fastjson2/util/IOUtils.java b/core/src/main/java/com/alibaba/fastjson2/util/IOUtils.java index f7a3502b1..80d621725 100644 --- a/core/src/main/java/com/alibaba/fastjson2/util/IOUtils.java +++ b/core/src/main/java/com/alibaba/fastjson2/util/IOUtils.java @@ -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) {