Binary incompatible serializer changes
- If the field type is fixed and the type is final, Class info can be omitted
- Annotations serializer to use optimization based on the fact Map<String, String> and non-null key/value
- Reduce number of Map copy required for ImmutableMap serializer
- Reduce number of array copy behind Immutable{List, Set} serializer
Change-Id: Ie467a943a33fbfb43b289b8b71ad91ee5890bfb0
diff --git a/core/store/serializers/src/main/java/org/onosproject/store/serializers/ImmutableListSerializer.java b/core/store/serializers/src/main/java/org/onosproject/store/serializers/ImmutableListSerializer.java
index b5bd490..95aa4ad 100644
--- a/core/store/serializers/src/main/java/org/onosproject/store/serializers/ImmutableListSerializer.java
+++ b/core/store/serializers/src/main/java/org/onosproject/store/serializers/ImmutableListSerializer.java
@@ -20,7 +20,6 @@
import com.esotericsoftware.kryo.io.Input;
import com.esotericsoftware.kryo.io.Output;
import com.google.common.collect.ImmutableList;
-import com.google.common.collect.ImmutableList.Builder;
/**
* Creates {@link ImmutableList} serializer instance.
@@ -44,12 +43,19 @@
@Override
public ImmutableList<?> read(Kryo kryo, Input input,
- Class<ImmutableList<?>> type) {
+ Class<ImmutableList<?>> type) {
final int size = input.readInt();
- Builder<Object> builder = ImmutableList.builder();
- for (int i = 0; i < size; ++i) {
- builder.add(kryo.readClassAndObject(input));
+ switch (size) {
+ case 0:
+ return ImmutableList.of();
+ case 1:
+ return ImmutableList.of(kryo.readClassAndObject(input));
+ default:
+ Object[] elms = new Object[size];
+ for (int i = 0; i < size; ++i) {
+ elms[i] = kryo.readClassAndObject(input);
+ }
+ return ImmutableList.copyOf(elms);
}
- return builder.build();
}
}