mirror of
https://github.com/alibaba/fastjson.git
synced 2026-10-29 14:10:25 +08:00
optimize, less method call, improved performance
This commit is contained in:
@@ -169,7 +169,7 @@ public class DefaultJSONParser implements Closeable {
|
||||
|
||||
//getInnerMap
|
||||
final boolean allowISO8601DateFormat = (lexer.features & Feature.AllowISO8601DateFormat.mask) != 0;
|
||||
final boolean disableCircularReferenceDetect = (lexer.features & Feature.DisableCircularReferenceDetect.mask) != 0;
|
||||
final boolean disableCircularReferenceDetect = lexer.disableCircularReferenceDetect;
|
||||
|
||||
ParseContext context = this.contex;
|
||||
try {
|
||||
@@ -684,7 +684,7 @@ public class DefaultJSONParser implements Closeable {
|
||||
}
|
||||
|
||||
ParseContext context = this.contex;
|
||||
if ((lexer.features & Feature.DisableCircularReferenceDetect.mask) == 0) {
|
||||
if (!lexer.disableCircularReferenceDetect) {
|
||||
setContext(this.contex, array, fieldName);
|
||||
}
|
||||
try {
|
||||
@@ -1061,7 +1061,7 @@ public class DefaultJSONParser implements Closeable {
|
||||
throw new JSONException("syntax error, expect [, actual " + JSONToken.name(token) + ", pos " + lexer.pos);
|
||||
}
|
||||
|
||||
final boolean disableCircularReferenceDetect = (lexer.features & Feature.DisableCircularReferenceDetect.mask) != 0;
|
||||
final boolean disableCircularReferenceDetect = lexer.disableCircularReferenceDetect;
|
||||
|
||||
ParseContext context = this.contex;
|
||||
if (!disableCircularReferenceDetect) {
|
||||
@@ -1262,7 +1262,7 @@ public class DefaultJSONParser implements Closeable {
|
||||
}
|
||||
|
||||
public void setContext(ParseContext context) {
|
||||
if ((lexer.features & Feature.DisableCircularReferenceDetect.mask) != 0) {
|
||||
if (lexer.disableCircularReferenceDetect) {
|
||||
return;
|
||||
}
|
||||
this.contex = context;
|
||||
@@ -1275,7 +1275,7 @@ public class DefaultJSONParser implements Closeable {
|
||||
}
|
||||
|
||||
protected ParseContext setContext(ParseContext parent, Object object, Object fieldName) {
|
||||
if ((lexer.features & Feature.DisableCircularReferenceDetect.mask) != 0) {
|
||||
if (lexer.disableCircularReferenceDetect) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@@ -78,6 +78,9 @@ public final class JSONLexer {
|
||||
|
||||
protected final String text;
|
||||
protected final int len;
|
||||
|
||||
protected String stringDefaultValue;
|
||||
public boolean disableCircularReferenceDetect;
|
||||
|
||||
public JSONLexer(String input){
|
||||
this(input, JSON.DEFAULT_PARSER_FEATURE);
|
||||
@@ -114,6 +117,11 @@ public final class JSONLexer {
|
||||
if (ch == 65279) {
|
||||
next();
|
||||
}
|
||||
|
||||
stringDefaultValue = (features & Feature.InitStringFieldAsEmpty.mask) != 0 //
|
||||
? "" //
|
||||
: null;
|
||||
disableCircularReferenceDetect = (features & Feature.DisableCircularReferenceDetect.mask) != 0;
|
||||
}
|
||||
|
||||
public final int token() {
|
||||
@@ -140,6 +148,13 @@ public final class JSONLexer {
|
||||
} else {
|
||||
features &= ~feature.mask;
|
||||
}
|
||||
|
||||
if (feature == Feature.InitStringFieldAsEmpty) {
|
||||
stringDefaultValue = (features & Feature.InitStringFieldAsEmpty.mask) != 0 //
|
||||
? "" //
|
||||
: null;
|
||||
}
|
||||
disableCircularReferenceDetect = (features & Feature.DisableCircularReferenceDetect.mask) != 0;
|
||||
}
|
||||
|
||||
public final boolean isEnabled(Feature feature) {
|
||||
@@ -526,12 +541,6 @@ public final class JSONLexer {
|
||||
return JSONToken.name(token);
|
||||
}
|
||||
|
||||
private String stringDefaultValue() {
|
||||
return (features & Feature.InitStringFieldAsEmpty.mask) != 0 //
|
||||
? "" //
|
||||
: null;
|
||||
}
|
||||
|
||||
public final Number integerValue() throws NumberFormatException {
|
||||
long result = 0;
|
||||
boolean negative = false;
|
||||
@@ -2031,7 +2040,7 @@ public final class JSONLexer {
|
||||
|
||||
if (!charArrayCompare(fieldName)) {
|
||||
matchStat = NOT_MATCH_NAME;
|
||||
return stringDefaultValue();
|
||||
return stringDefaultValue;
|
||||
}
|
||||
|
||||
// int index = bp + fieldName.length;
|
||||
@@ -2050,7 +2059,7 @@ public final class JSONLexer {
|
||||
if (chLocal != '"') {
|
||||
matchStat = NOT_MATCH;
|
||||
|
||||
return stringDefaultValue();
|
||||
return stringDefaultValue;
|
||||
}
|
||||
|
||||
final char quoteChar = '"';
|
||||
@@ -2107,6 +2116,20 @@ public final class JSONLexer {
|
||||
EOI //
|
||||
: text.charAt(index);
|
||||
}
|
||||
|
||||
if (chLocal == ',') {
|
||||
bp = endIndex;
|
||||
// this.next();
|
||||
{
|
||||
int index = ++bp;
|
||||
this.ch = (index >= this.len ? //
|
||||
EOI //
|
||||
: text.charAt(index));
|
||||
}
|
||||
matchStat = VALUE;
|
||||
token = JSONToken.COMMA;
|
||||
return strVal;
|
||||
}
|
||||
|
||||
if (chLocal == '}') {
|
||||
chLocal = charAt(++endIndex);
|
||||
@@ -2128,12 +2151,12 @@ public final class JSONLexer {
|
||||
ch = EOI;
|
||||
} else {
|
||||
matchStat = NOT_MATCH;
|
||||
return stringDefaultValue();
|
||||
return stringDefaultValue;
|
||||
}
|
||||
matchStat = END;
|
||||
} else {
|
||||
matchStat = NOT_MATCH;
|
||||
return stringDefaultValue();
|
||||
return stringDefaultValue;
|
||||
}
|
||||
|
||||
return strVal;
|
||||
|
||||
@@ -175,6 +175,8 @@ public class JavaBeanDeserializer implements ObjectDeserializer {
|
||||
lexer.nextToken(JSONToken.COMMA);
|
||||
return null;
|
||||
}
|
||||
|
||||
final boolean disableCircularReferenceDetect = lexer.disableCircularReferenceDetect;
|
||||
|
||||
ParseContext context = parser.contex;
|
||||
if (object != null && context != null) {
|
||||
@@ -423,7 +425,9 @@ public class JavaBeanDeserializer implements ObjectDeserializer {
|
||||
if (object == null) {
|
||||
fieldValues = new HashMap<String, Object>(this.fieldDeserializers.length);
|
||||
}
|
||||
childContext = parser.setContext(context, object, fieldName);
|
||||
if (!disableCircularReferenceDetect) {
|
||||
childContext = parser.setContext(context, object, fieldName);
|
||||
}
|
||||
}
|
||||
|
||||
if (matchField) {
|
||||
|
||||
Reference in New Issue
Block a user