From 928e2b904db713d8d85e7bce0391f53f55928af9 Mon Sep 17 00:00:00 2001 From: Robert Muir Date: Thu, 5 May 2016 03:42:14 -0400 Subject: [PATCH] painless: optimize/simplify dynamic field and method access --- .../java/org/elasticsearch/painless/Def.java | 52 +++++-------------- 1 file changed, 12 insertions(+), 40 deletions(-) diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/Def.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/Def.java index 71c7de23c85..b8cf7fb6069 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/Def.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/Def.java @@ -242,18 +242,16 @@ public class Def { } public static Method getMethod(final Object owner, final String name, final Definition definition) { - Struct struct = null; Class clazz = owner.getClass(); - Method method = null; while (clazz != null) { - struct = definition.classes.get(clazz); + Struct struct = definition.classes.get(clazz); if (struct != null) { - method = struct.methods.get(name); + Method method = struct.methods.get(name); if (method != null) { - break; + return method; } } @@ -261,45 +259,31 @@ public class Def { struct = definition.classes.get(iface); if (struct != null) { - method = struct.methods.get(name); + Method method = struct.methods.get(name); if (method != null) { - break; + return method; } } } - if (struct != null) { - method = struct.methods.get(name); - - if (method != null) { - break; - } - } - clazz = clazz.getSuperclass(); } - if (struct == null) { - throw new IllegalArgumentException("Unable to find a dynamic struct for class [" + owner.getClass() + "]."); - } - - return method; + return null; } public static Field getField(final Object owner, final String name, final Definition definition) { - Struct struct = null; Class clazz = owner.getClass(); - Field field = null; while (clazz != null) { - struct = definition.classes.get(clazz); + Struct struct = definition.classes.get(clazz); if (struct != null) { - field = struct.members.get(name); + Field field = struct.members.get(name); if (field != null) { - break; + return field; } } @@ -307,30 +291,18 @@ public class Def { struct = definition.classes.get(iface); if (struct != null) { - field = struct.members.get(name); + Field field = struct.members.get(name); if (field != null) { - break; + return field; } } } - if (struct != null) { - field = struct.members.get(name); - - if (field != null) { - break; - } - } - clazz = clazz.getSuperclass(); } - if (struct == null) { - throw new IllegalArgumentException("Unable to find a dynamic struct for class [" + owner.getClass() + "]."); - } - - return field; + return null; } public static Transform getTransform(Class fromClass, Class toClass, final Definition definition) {