Optimise for encoding String primitive data types

We typically have many more string primitives than anything else
This commit is contained in:
David Maplesden 2019-09-17 09:48:34 +12:00 committed by James Agnew
parent 8b84b8ffea
commit 1f253856cf

View File

@ -224,13 +224,24 @@ public class JsonParser extends BaseParser implements IJsonLikeParser {
} }
case PRIMITIVE_DATATYPE: { case PRIMITIVE_DATATYPE: {
final IPrimitiveType<?> value = (IPrimitiveType<?>) theNextValue; final IPrimitiveType<?> value = (IPrimitiveType<?>) theNextValue;
if (isBlank(value.getValueAsString())) { final String valueStr = value.getValueAsString();
if (isBlank(valueStr)) {
if (theForceEmpty) { if (theForceEmpty) {
theEventWriter.writeNull(); theEventWriter.writeNull();
} }
break; break;
} }
// check for the common case first - String value types
if (value.getValue() instanceof String) {
if (theChildName != null) {
theEventWriter.write(theChildName, valueStr);
} else {
theEventWriter.write(valueStr);
}
break;
}
if (value instanceof IBaseIntegerDatatype) { if (value instanceof IBaseIntegerDatatype) {
if (theChildName != null) { if (theChildName != null) {
write(theEventWriter, theChildName, ((IBaseIntegerDatatype) value).getValue()); write(theEventWriter, theChildName, ((IBaseIntegerDatatype) value).getValue());
@ -262,7 +273,6 @@ public class JsonParser extends BaseParser implements IJsonLikeParser {
} }
} }
} else { } else {
String valueStr = value.getValueAsString();
if (theChildName != null) { if (theChildName != null) {
write(theEventWriter, theChildName, valueStr); write(theEventWriter, theChildName, valueStr);
} else { } else {