list addition optimization (#1038)

* list addition optimization

* Optimized imports

Optimized imports
This commit is contained in:
guptasourabh 2017-03-17 09:46:38 +05:30 committed by inder123
parent fd37cf1d0d
commit 8101ab74e9
2 changed files with 5 additions and 5 deletions

View File

@ -16,7 +16,6 @@
package com.google.gson;
import com.google.gson.stream.JsonReader;
import java.lang.reflect.Type;
import java.sql.Timestamp;
import java.text.DateFormat;
@ -32,6 +31,7 @@ import com.google.gson.internal.Excluder;
import com.google.gson.internal.bind.TreeTypeAdapter;
import com.google.gson.internal.bind.TypeAdapters;
import com.google.gson.reflect.TypeToken;
import com.google.gson.stream.JsonReader;
import static com.google.gson.Gson.DEFAULT_COMPLEX_MAP_KEYS;
import static com.google.gson.Gson.DEFAULT_ESCAPE_HTML;
@ -519,8 +519,7 @@ public final class GsonBuilder {
|| typeAdapter instanceof JsonDeserializer<?>
|| typeAdapter instanceof TypeAdapter<?>);
if (typeAdapter instanceof JsonDeserializer || typeAdapter instanceof JsonSerializer) {
hierarchyFactories.add(0,
TreeTypeAdapter.newTypeHierarchyFactory(baseType, typeAdapter));
hierarchyFactories.add(TreeTypeAdapter.newTypeHierarchyFactory(baseType, typeAdapter));
}
if (typeAdapter instanceof TypeAdapter<?>) {
factories.add(TypeAdapters.newTypeHierarchyFactory(baseType, (TypeAdapter)typeAdapter));
@ -560,9 +559,10 @@ public final class GsonBuilder {
* @return an instance of Gson configured with the options currently set in this builder
*/
public Gson create() {
List<TypeAdapterFactory> factories = new ArrayList<TypeAdapterFactory>();
List<TypeAdapterFactory> factories = new ArrayList<TypeAdapterFactory>(this.factories.size() + this.hierarchyFactories.size() + 3);
factories.addAll(this.factories);
Collections.reverse(factories);
Collections.reverse(this.hierarchyFactories);
factories.addAll(this.hierarchyFactories);
addTypeAdaptersForDate(datePattern, dateStyle, timeStyle, factories);

View File

@ -270,7 +270,7 @@ public class ProtoTypeAdapter
if (jsonElement.isJsonArray()) {
// Handling array
Collection<EnumValueDescriptor> enumCollection =
new ArrayList<EnumValueDescriptor>();
new ArrayList<EnumValueDescriptor>(jsonElement.getAsJsonArray().size());
for (JsonElement element : jsonElement.getAsJsonArray()) {
enumCollection.add(
findValueByNameAndExtension(fieldDescriptor.getEnumType(), element));