Speed up service adapter object methods 28/74028/3
authorRobert Varga <robert.varga@pantheon.tech>
Fri, 13 Jul 2018 16:48:36 +0000 (18:48 +0200)
committerTom Pantelis <tompantelis@gmail.com>
Sat, 14 Jul 2018 03:47:00 +0000 (03:47 +0000)
Rather than checking the method name twice inline co-locate signature
checks and result return.

Change-Id: Ic64ab8fb9089ef344e999430760155f406004cf6
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
binding/mdsal-binding-dom-adapter/src/main/java/org/opendaylight/mdsal/binding/dom/adapter/RpcServiceAdapter.java

index 77a6ded9c2499440bd05140336940f65b5a0f1a4..f7ec742788d882d3b078adc6917f4786ce506028 100644 (file)
@@ -89,37 +89,28 @@ class RpcServiceAdapter implements InvocationHandler {
             return rpc.invoke((DataObject) args[0]);
         }
 
-        if (isObjectMethod(method)) {
-            return callObjectMethod(proxy, method, args);
-        }
-        throw new UnsupportedOperationException("Method " + method.toString() + "is unsupported.");
-    }
-
-    private static boolean isObjectMethod(final Method method) {
         switch (method.getName()) {
             case "toString":
-                return method.getReturnType().equals(String.class) && method.getParameterTypes().length == 0;
+                if (method.getReturnType().equals(String.class) && method.getParameterTypes().length == 0) {
+                    return type.getName() + "$Adapter{delegate=" + delegate.toString() + "}";
+                }
+                break;
             case "hashCode":
-                return method.getReturnType().equals(int.class) && method.getParameterTypes().length == 0;
+                if (method.getReturnType().equals(int.class) && method.getParameterTypes().length == 0) {
+                    return System.identityHashCode(proxy);
+                }
+                break;
             case "equals":
-                return method.getReturnType().equals(boolean.class) && method.getParameterTypes().length == 1
-                        && method.getParameterTypes()[0] == Object.class;
+                if (method.getReturnType().equals(boolean.class) && method.getParameterTypes().length == 1
+                        && method.getParameterTypes()[0] == Object.class) {
+                    return proxy == args[0];
+                }
+                break;
             default:
-                return false;
+                break;
         }
-    }
 
-    private Object callObjectMethod(final Object self, final Method method, final Object[] args) {
-        switch (method.getName()) {
-            case "toString":
-                return type.getName() + "$Adapter{delegate=" + delegate.toString() + "}";
-            case "hashCode":
-                return System.identityHashCode(self);
-            case "equals":
-                return self == args[0];
-            default:
-                return null;
-        }
+        throw new UnsupportedOperationException("Method " + method.toString() + "is unsupported.");
     }
 
     private abstract class RpcInvocationStrategy {