Skip ArrayList instantiation during deserialization
authorRobert Varga <rovarga@cisco.com>
Wed, 25 Feb 2015 11:24:36 +0000 (12:24 +0100)
committerRobert Varga <rovarga@cisco.com>
Wed, 25 Feb 2015 11:28:54 +0000 (12:28 +0100)
We use the ArrayList just as an index holder, after which we just
extract the underlying array. The libraries by default perform a copy
and then JIT has to prove what is going on to remove that overhead.

Let's make it super-easy instead by filling the array ourselves.

Change-Id: Ib48992538b3cd8a9a0c11011fe444e24b23dc825
Signed-off-by: Robert Varga <rovarga@cisco.com>
code-generator/binding-data-codec/src/main/java/org/opendaylight/yangtools/binding/data/codec/impl/IdentifiableItemCodec.java

index 47a24fb593a40537781dc57994b1f9049325d9f3..09231179d2a4731fe48f1cf8311ff7d18da13f63 100644 (file)
@@ -95,15 +95,17 @@ final class IdentifiableItemCodec implements Codec<NodeIdentifierWithPredicates,
 
     @Override
     public IdentifiableItem<?, ?> deserialize(final NodeIdentifierWithPredicates input) {
-        final ArrayList<Object> bindingValues = new ArrayList<>(keysInBindingOrder.size());
+        final Object[] bindingValues = new Object[keysInBindingOrder.size()];
+        int offset = 0;
+
         for (final QName key : keysInBindingOrder) {
             final Object yangValue = input.getKeyValues().get(key);
-            bindingValues.add(keyValueContexts.get(key).deserialize(yangValue));
+            bindingValues[offset++] = keyValueContexts.get(key).deserialize(yangValue);
         }
 
         final Identifier<?> identifier;
         try {
-            identifier = (Identifier<?>) ctorInvoker.invokeExact(ctor, bindingValues.toArray());
+            identifier = (Identifier<?>) ctorInvoker.invokeExact(ctor, bindingValues);
         } catch (Throwable e) {
             throw Throwables.propagate(e);
         }