Skip to content

Commit

Permalink
optimize serialize, remove unused code
Browse files Browse the repository at this point in the history
  • Loading branch information
wenshao committed Jul 26, 2023
1 parent 62bb3d9 commit ddb1c52
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public static void fastjson2() {
long millis = System.currentTimeMillis() - start;
System.out.println("fastjson2 millis : " + millis);
// zulu8.58.0.13 : 336 347 317
// zulu11.52.13 : 337 314 289 2888 2606
// zulu11.52.13 : 337 314 289 2888 2606 2441
// zulu17.40.19 : 317 320 285
// zulu17.40.19_vec : 267 250
// graalvm_17.0.7 207
Expand Down
4 changes: 0 additions & 4 deletions core/src/main/java/com/alibaba/fastjson2/JSONWriter.java
Original file line number Diff line number Diff line change
Expand Up @@ -254,10 +254,6 @@ public final boolean isRefDetect(Object object) {
&& !ObjectWriterProvider.isNotReferenceDetect(object.getClass());
}

public final void vv() {
System.out.println("");
}

public final boolean containsReference(Object value) {
return refs != null && refs.containsKey(value);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ public void writeListValue(JSONWriter jsonWriter, List list) {
itemObjectWriter = previousObjectWriter;
itemRefDetect = previousItemRefDetect;
} else {
itemRefDetect = jsonWriter.isRefDetect();
itemRefDetect = (features & ReferenceDetection.mask) != 0;
itemObjectWriter = getItemWriter(jsonWriter, itemClass);
previousClass = itemClass;
previousObjectWriter = itemObjectWriter;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1828,12 +1828,12 @@ private void gwFieldValueObject(

int REF_DETECT = mwc.var("REF_DETECT");

mw.visitVarInsn(Opcodes.ALOAD, JSON_WRITER);
if (fieldClass == Object.class) {
mw.visitVarInsn(Opcodes.ALOAD, JSON_WRITER);
mw.visitVarInsn(Opcodes.ALOAD, FIELD_VALUE);
mw.visitMethodInsn(Opcodes.INVOKEVIRTUAL, TYPE_JSON_WRITER, "isRefDetect", "(Ljava/lang/Object;)Z", false);
} else {
mw.visitMethodInsn(Opcodes.INVOKEVIRTUAL, TYPE_JSON_WRITER, "isRefDetect", "()Z", false);
mwc.genIsEnabled(JSONWriter.Feature.ReferenceDetection.mask, null);
}
mw.visitInsn(Opcodes.DUP);
mw.visitVarInsn(Opcodes.ISTORE, REF_DETECT);
Expand Down Expand Up @@ -2520,12 +2520,12 @@ private void gwFieldValueObjectJSONB(

int REF_DETECT = mwc.var("REF_DETECT");

mw.visitVarInsn(Opcodes.ALOAD, JSON_WRITER);
if (fieldClass == Object.class) {
mw.visitVarInsn(Opcodes.ALOAD, JSON_WRITER);
mw.visitVarInsn(Opcodes.ALOAD, FIELD_VALUE);
mw.visitMethodInsn(Opcodes.INVOKEVIRTUAL, TYPE_JSON_WRITER, "isRefDetect", "(Ljava/lang/Object;)Z", false);
} else {
mw.visitMethodInsn(Opcodes.INVOKEVIRTUAL, TYPE_JSON_WRITER, "isRefDetect", "()Z", false);
mwc.genIsEnabled(JSONWriter.Feature.ReferenceDetection.mask, null);
}
mw.visitInsn(Opcodes.DUP);
mw.visitVarInsn(Opcodes.ISTORE, REF_DETECT);
Expand Down Expand Up @@ -3714,7 +3714,9 @@ void genIsEnabled(long features, Label elseLabel) {
mw.visitInsn(Opcodes.LAND);
mw.visitInsn(Opcodes.LCONST_0);
mw.visitInsn(Opcodes.LCMP);
mw.visitJumpInsn(Opcodes.IFEQ, elseLabel);
if (elseLabel != null) {
mw.visitJumpInsn(Opcodes.IFEQ, elseLabel);
}
}

void genIsDisabled(long features, Label elseLabel) {
Expand Down

0 comments on commit ddb1c52

Please sign in to comment.