remove unused code

This commit is contained in:
高铁 2025-02-25 18:58:40 +08:00
parent d11f0ef178
commit c9e109020e
3 changed files with 28 additions and 15 deletions

View File

@ -17,6 +17,8 @@ import java.lang.invoke.MethodHandles;
import java.lang.invoke.MethodType;
import java.util.concurrent.TimeUnit;
import static com.alibaba.fastjson2.util.JDKUtils.INDEX_OF_CHAR_LATIN1;
public class BytesAsciiCheck {
static byte[] bytes;
static char[] chars;
@ -92,7 +94,7 @@ public class BytesAsciiCheck {
@Benchmark
public void indexOfSlash(Blackhole bh) throws Throwable {
bh.consume(com.alibaba.fastjson2.util.IOUtils.indexOfSlash(bytes, 0, bytes.length));
bh.consume(indexOfSlash(bytes, 0, bytes.length));
}
@Benchmark
@ -110,6 +112,17 @@ public class BytesAsciiCheck {
bh.consume(str.indexOf('\\'));
}
public static int indexOfSlash(byte[] value, int fromIndex, int max) {
if (INDEX_OF_CHAR_LATIN1 == null) {
return com.alibaba.fastjson2.util.IOUtils.indexOfSlashV(value, fromIndex, max);
}
try {
return (int) INDEX_OF_CHAR_LATIN1.invokeExact(value, (int) '\\', fromIndex, max);
} catch (Throwable e) {
throw new JSONException(e.getMessage());
}
}
private static int indexOfChar(byte[] bytes, int ch, int fromIndex, int toIndex) {
try {
return (int) INDEX_OF_CHAR.invokeExact(bytes, ch, fromIndex, toIndex);

View File

@ -1563,17 +1563,6 @@ public class IOUtils {
return indexOfChar(value, '\n', i, max);
}
public static int indexOfSlash(byte[] value, int fromIndex, int max) {
if (INDEX_OF_CHAR_LATIN1 == null) {
return indexOfSlashV(value, fromIndex, max);
}
try {
return (int) INDEX_OF_CHAR_LATIN1.invokeExact(value, (int) '\\', fromIndex, max);
} catch (Throwable e) {
throw new JSONException(e.getMessage());
}
}
public static int indexOfSlashV(byte[] value, int fromIndex, int max) {
int i = fromIndex;
long address = ARRAY_BYTE_BASE_OFFSET + fromIndex;

View File

@ -403,16 +403,27 @@ public class IOUtilsTest {
public void indexOfSlash() {
byte[] bytes = "\\b\\d\\".getBytes(StandardCharsets.UTF_8);
assertEquals(2,
IOUtils.indexOfSlash(
indexOfSlash(
bytes, 1, bytes.length));
assertEquals(0,
IOUtils.indexOfSlash(
indexOfSlash(
bytes, 0, bytes.length));
assertEquals(4,
IOUtils.indexOfSlash(
indexOfSlash(
bytes, 3, bytes.length));
}
public static int indexOfSlash(byte[] value, int fromIndex, int max) {
if (INDEX_OF_CHAR_LATIN1 == null) {
return IOUtils.indexOfSlashV(value, fromIndex, max);
}
try {
return (int) INDEX_OF_CHAR_LATIN1.invokeExact(value, (int) '\\', fromIndex, max);
} catch (Throwable e) {
throw new JSONException(e.getMessage());
}
}
@Test
public void convEndian() throws Throwable {
Random r = new Random();