exposed final fields of Pair for fast access. Pair is used quite a bit during serialization because of its use in ref stack.
This commit is contained in:
parent
fff9147988
commit
610580b8d9
@ -84,8 +84,8 @@ abstract class JsonDeserializationVisitor<T> implements ObjectNavigator.Visitor
|
||||
if (element == null || element.isJsonNull()) {
|
||||
return null;
|
||||
}
|
||||
Type objType = pair.getSecond().getType();
|
||||
return (pair.getFirst()).deserialize(element, objType, context);
|
||||
Type objType = pair.second.type;
|
||||
return (pair.first).deserialize(element, objType, context);
|
||||
}
|
||||
|
||||
final Object visitChildAsObject(Type childType, JsonElement jsonChild) {
|
||||
|
@ -179,8 +179,8 @@ final class JsonSerializationVisitor implements ObjectNavigator.Visitor {
|
||||
if (pair == null) {
|
||||
return null;
|
||||
}
|
||||
JsonSerializer serializer = pair.getFirst();
|
||||
objTypePair = pair.getSecond();
|
||||
JsonSerializer serializer = pair.first;
|
||||
objTypePair = pair.second;
|
||||
start(objTypePair);
|
||||
try {
|
||||
JsonElement element =
|
||||
|
@ -78,7 +78,7 @@ final class MemoryRefStack {
|
||||
|
||||
for (ObjectTypePair stackObject : stack) {
|
||||
if (stackObject.getObject() == obj.getObject()
|
||||
&& stackObject.getType().equals(obj.getType()) ) {
|
||||
&& stackObject.type.equals(obj.type) ) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -91,7 +91,7 @@ final class ObjectNavigator {
|
||||
* If a field is null, it does not get visited.
|
||||
*/
|
||||
public void accept(Visitor visitor) {
|
||||
TypeInfo objTypeInfo = new TypeInfo(objTypePair.getType());
|
||||
TypeInfo objTypeInfo = new TypeInfo(objTypePair.type);
|
||||
if (exclusionStrategy.shouldSkipClass(objTypeInfo.getRawClass())) {
|
||||
return;
|
||||
}
|
||||
@ -106,7 +106,7 @@ final class ObjectNavigator {
|
||||
visitor.start(objTypePair);
|
||||
try {
|
||||
if (objTypeInfo.isArray()) {
|
||||
visitor.visitArray(objectToVisit, objTypePair.getType());
|
||||
visitor.visitArray(objectToVisit, objTypePair.type);
|
||||
} else if (objTypeInfo.getActualType() == Object.class
|
||||
&& isPrimitiveOrString(objectToVisit)) {
|
||||
// TODO(Joel): this is only used for deserialization of "primitives"
|
||||
@ -116,7 +116,7 @@ final class ObjectNavigator {
|
||||
} else {
|
||||
visitor.startVisitingObject(objectToVisit);
|
||||
ObjectTypePair currObjTypePair = objTypePair.toMoreSpecificType();
|
||||
Class<?> topLevelClass = new TypeInfo(currObjTypePair.getType()).getRawClass();
|
||||
Class<?> topLevelClass = new TypeInfo(currObjTypePair.type).getRawClass();
|
||||
for (Class<?> curr = topLevelClass; curr != null && !curr.equals(Object.class);
|
||||
curr = curr.getSuperclass()) {
|
||||
if (!curr.isSynthetic()) {
|
||||
@ -145,7 +145,7 @@ final class ObjectNavigator {
|
||||
|| exclusionStrategy.shouldSkipClass(fieldAttributes.getDeclaredClass())) {
|
||||
continue; // skip
|
||||
} else {
|
||||
TypeInfo fieldTypeInfo = TypeInfoFactory.getTypeInfoForField(f, objTypePair.getType());
|
||||
TypeInfo fieldTypeInfo = TypeInfoFactory.getTypeInfoForField(f, objTypePair.type);
|
||||
Type declaredTypeOfField = fieldTypeInfo.getActualType();
|
||||
boolean visitedWithCustomHandler =
|
||||
visitor.visitFieldUsingCustomHandler(f, declaredTypeOfField, obj);
|
||||
|
@ -24,7 +24,7 @@ import java.lang.reflect.Type;
|
||||
*/
|
||||
final class ObjectTypePair {
|
||||
private Object obj;
|
||||
private final Type type;
|
||||
final Type type;
|
||||
private final boolean preserveType;
|
||||
|
||||
ObjectTypePair(Object obj, Type type, boolean preserveType) {
|
||||
|
@ -17,19 +17,11 @@ package com.google.gson;
|
||||
|
||||
final class Pair<FIRST, SECOND> {
|
||||
|
||||
private final FIRST first;
|
||||
private final SECOND second;
|
||||
final FIRST first;
|
||||
final SECOND second;
|
||||
|
||||
Pair(FIRST first, SECOND second) {
|
||||
this.first = first;
|
||||
this.second = second;
|
||||
}
|
||||
|
||||
public FIRST getFirst() {
|
||||
return first;
|
||||
}
|
||||
|
||||
public SECOND getSecond() {
|
||||
return second;
|
||||
}
|
||||
}
|
||||
|
@ -33,7 +33,7 @@ import java.lang.reflect.Field;
|
||||
*
|
||||
* @author Joel Leitch
|
||||
*/
|
||||
class SerializedNameAnnotationInterceptingNamingPolicy implements FieldNamingStrategy {
|
||||
final class SerializedNameAnnotationInterceptingNamingPolicy implements FieldNamingStrategy {
|
||||
private static final JsonFieldNameValidator fieldNameValidator = new JsonFieldNameValidator();
|
||||
private final FieldNamingStrategy delegate;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user