optimize readBool & readString null

This commit is contained in:
wenshao 2025-02-27 06:19:24 +08:00
parent c12ef42a7e
commit 0fccd4ee5b
5 changed files with 18 additions and 6 deletions

View File

@ -14,9 +14,9 @@ public class TwitterParseStringTest {
}
long millis = System.currentTimeMillis() - start;
System.out.println("fastjson2 millis : " + millis);
// zulu8.70.0.23 : 4128
// zulu8.70.0.23 : 4128 3465
// zulu11.64.19 :
// zulu17.42.19 :
// zulu17.42.19 : 3465 3415 3383
}
}
@ -35,8 +35,8 @@ public class TwitterParseStringTest {
}
public static void main(String[] args) throws Exception {
// fastjson2();
jackson();
fastjson2();
// jackson();
// fastjson1();
// gson();
// wastjson();

View File

@ -1392,6 +1392,9 @@ final class JSONReaderASCII
this.ch = (char) (ch & 0xFF);
this.offset = offset;
return str;
} else if (ch == 'n') {
readNull();
return null;
}
return readStringNotMatch();

View File

@ -3154,6 +3154,9 @@ final class JSONReaderUTF16
this.ch = (char) ch;
this.offset = offset;
return str;
} else if (quote == 'n') {
readNull();
return null;
}
return readStringNotMatch();

View File

@ -4697,9 +4697,9 @@ class JSONReaderUTF8
@Override
public String readString() {
if (ch == '"' || ch == '\'') {
char quote = this.ch;
if (quote == '"' || quote == '\'') {
final byte[] bytes = this.bytes;
char quote = this.ch;
int valueLength;
int offset = this.offset;
final int start = offset, end = this.end;
@ -4886,6 +4886,9 @@ class JSONReaderUTF8
this.ch = (char) ch;
this.offset = offset;
return str;
} else if (quote == 'n') {
readNull();
return null;
}
return readStringNotMatch();

View File

@ -2808,6 +2808,9 @@ public class ObjectReaderCreatorASM
mw.invokevirtual("java/lang/String", "toUpperCase", "()Ljava/lang/String;");
}
mw.visitLabel(null_);
} else if (fieldClass == Boolean.class) {
mw.aload(JSON_READER);
mw.invokevirtual(TYPE_JSON_READER, "readBool", "()Ljava/lang/Boolean;");
} else if (fieldClass == Byte.class) {
mw.aload(JSON_READER);
mw.invokevirtual(TYPE_JSON_READER, "readInt8", "()Ljava/lang/Byte;");