Skip to content

Commit

Permalink
optimize JSONReader for JDK8
Browse files Browse the repository at this point in the history
  • Loading branch information
wenshao committed Feb 11, 2025
1 parent cc5884f commit 0ffeb27
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 11 deletions.
8 changes: 4 additions & 4 deletions core/src/main/java/com/alibaba/fastjson2/JSONReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -3240,7 +3240,7 @@ protected final String toString(Map object) {

public static JSONReader of(byte[] utf8Bytes) {
Context context = createReadContext();
if (PREDICATE_IS_ASCII.test(utf8Bytes)) {
if (PREDICATE_IS_ASCII != null && PREDICATE_IS_ASCII.test(utf8Bytes)) {
return new JSONReaderASCII(context, null, utf8Bytes, 0, utf8Bytes.length);
}

Expand All @@ -3249,15 +3249,15 @@ public static JSONReader of(byte[] utf8Bytes) {

@Deprecated
public static JSONReader of(Context context, byte[] utf8Bytes) {
if (PREDICATE_IS_ASCII.test(utf8Bytes)) {
if (PREDICATE_IS_ASCII != null && PREDICATE_IS_ASCII.test(utf8Bytes)) {
return new JSONReaderASCII(context, null, utf8Bytes, 0, utf8Bytes.length);
}

return new JSONReaderUTF8(context, null, utf8Bytes, 0, utf8Bytes.length);
}

public static JSONReader of(byte[] utf8Bytes, Context context) {
if (PREDICATE_IS_ASCII.test(utf8Bytes)) {
if (PREDICATE_IS_ASCII != null && PREDICATE_IS_ASCII.test(utf8Bytes)) {
return new JSONReaderASCII(context, null, utf8Bytes, 0, utf8Bytes.length);
}

Expand Down Expand Up @@ -3500,7 +3500,7 @@ public static JSONReader of(String str) {
int coder = STRING_CODER.applyAsInt(str);
if (coder == LATIN1) {
byte[] bytes = STRING_VALUE.apply(str);
if (PREDICATE_IS_ASCII.test(bytes)) {
if (PREDICATE_IS_ASCII != null && PREDICATE_IS_ASCII.test(bytes)) {
return new JSONReaderASCII(context, str, bytes, 0, bytes.length);
}
}
Expand Down
7 changes: 0 additions & 7 deletions core/src/main/java/com/alibaba/fastjson2/util/JDKUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -317,9 +317,6 @@ public class JDKUtils {
initErrorLast = e;
}
}
if (isAscii == null) {
isAscii = JDKUtils::isASCII;
}

PREDICATE_IS_ASCII = isAscii;
}
Expand Down Expand Up @@ -525,8 +522,4 @@ public static String latin1StringJDK8(byte[] bytes, int offset, int strlen) {
}
return STRING_CREATOR_JDK8.apply(chars, Boolean.TRUE);
}

static boolean isASCII(byte[] chars) {
return IOUtils.isASCII(chars, 0, chars.length);
}
}

0 comments on commit 0ffeb27

Please sign in to comment.