From 5b67ca39a136aa27e34adf1d8933a717c1dd6a75 Mon Sep 17 00:00:00 2001 From: Robert Varga Date: Mon, 4 May 2020 14:40:40 +0200 Subject: [PATCH] Eliminate KeyedListNodeCodecContext.Unordered.getKey() This method and the methodhandle invoker are completely superfluous, as we can directly access key() from the created object. While capturing a MethodHandle lowers what method can be invoked, it does not really buy us much, as the observed class will we always the same. That property is visible enough (wired through an invokeExact() on the constructor), hence JIT should be able to optimize without this help. Change-Id: Id24eac8e74782f750576c90d60485b2dcbdcff9e Signed-off-by: Robert Varga --- .../codec/impl/KeyedListNodeCodecContext.java | 25 +------------------ 1 file changed, 1 insertion(+), 24 deletions(-) diff --git a/binding/mdsal-binding-dom-codec/src/main/java/org/opendaylight/mdsal/binding/dom/codec/impl/KeyedListNodeCodecContext.java b/binding/mdsal-binding-dom-codec/src/main/java/org/opendaylight/mdsal/binding/dom/codec/impl/KeyedListNodeCodecContext.java index 5d8445e279..44151a7b81 100644 --- a/binding/mdsal-binding-dom-codec/src/main/java/org/opendaylight/mdsal/binding/dom/codec/impl/KeyedListNodeCodecContext.java +++ b/binding/mdsal-binding-dom-codec/src/main/java/org/opendaylight/mdsal/binding/dom/codec/impl/KeyedListNodeCodecContext.java @@ -12,10 +12,6 @@ import static org.opendaylight.mdsal.binding.spec.naming.BindingMapping.IDENTIFI import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap.Builder; -import java.lang.invoke.MethodHandle; -import java.lang.invoke.MethodHandles; -import java.lang.invoke.MethodType; -import java.lang.invoke.WrongMethodTypeException; import java.lang.reflect.Method; import java.util.List; import org.eclipse.jdt.annotation.NonNull; @@ -39,19 +35,9 @@ abstract class KeyedListNodeCodecContext> } private static final class Unordered> extends KeyedListNodeCodecContext { - private static final MethodType KEY_TYPE = MethodType.methodType(Object.class, DataObject.class); - - private final MethodHandle keyHandle; - Unordered(final DataContainerCodecPrototype prototype, final Method keyMethod, final IdentifiableItemCodec codec) { super(prototype, keyMethod, codec); - - try { - this.keyHandle = MethodHandles.publicLookup().unreflect(keyMethod).asType(KEY_TYPE); - } catch (IllegalAccessException | WrongMethodTypeException e) { - throw new LinkageError("Failed to acquire method " + keyMethod, e); - } } @Override @@ -60,19 +46,10 @@ abstract class KeyedListNodeCodecContext> final Builder builder = ImmutableMap.builderWithExpectedSize(size); for (MapEntryNode node : map.getValue()) { final D entry = fromMapEntry(node); - builder.put(getKey(entry), entry); + builder.put(entry.key(), entry); } return builder.build(); } - - @SuppressWarnings("checkstyle:illegalCatch") - private Object getKey(final D entry) { - try { - return keyHandle.invokeExact(entry); - } catch (Throwable e) { - throw new LinkageError("Failed to extract key from " + entry, e); - } - } } private final IdentifiableItemCodec codec; -- 2.36.6