painless: optimize/simplify dynamic field and method access
This commit is contained in:
parent
784c9e5fb9
commit
928e2b904d
|
@ -242,18 +242,16 @@ public class Def {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Method getMethod(final Object owner, final String name, final Definition definition) {
|
public static Method getMethod(final Object owner, final String name, final Definition definition) {
|
||||||
Struct struct = null;
|
|
||||||
Class<?> clazz = owner.getClass();
|
Class<?> clazz = owner.getClass();
|
||||||
Method method = null;
|
|
||||||
|
|
||||||
while (clazz != null) {
|
while (clazz != null) {
|
||||||
struct = definition.classes.get(clazz);
|
Struct struct = definition.classes.get(clazz);
|
||||||
|
|
||||||
if (struct != null) {
|
if (struct != null) {
|
||||||
method = struct.methods.get(name);
|
Method method = struct.methods.get(name);
|
||||||
|
|
||||||
if (method != null) {
|
if (method != null) {
|
||||||
break;
|
return method;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -261,45 +259,31 @@ public class Def {
|
||||||
struct = definition.classes.get(iface);
|
struct = definition.classes.get(iface);
|
||||||
|
|
||||||
if (struct != null) {
|
if (struct != null) {
|
||||||
method = struct.methods.get(name);
|
Method method = struct.methods.get(name);
|
||||||
|
|
||||||
if (method != null) {
|
if (method != null) {
|
||||||
break;
|
return method;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (struct != null) {
|
|
||||||
method = struct.methods.get(name);
|
|
||||||
|
|
||||||
if (method != null) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
clazz = clazz.getSuperclass();
|
clazz = clazz.getSuperclass();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (struct == null) {
|
return null;
|
||||||
throw new IllegalArgumentException("Unable to find a dynamic struct for class [" + owner.getClass() + "].");
|
|
||||||
}
|
|
||||||
|
|
||||||
return method;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Field getField(final Object owner, final String name, final Definition definition) {
|
public static Field getField(final Object owner, final String name, final Definition definition) {
|
||||||
Struct struct = null;
|
|
||||||
Class<?> clazz = owner.getClass();
|
Class<?> clazz = owner.getClass();
|
||||||
Field field = null;
|
|
||||||
|
|
||||||
while (clazz != null) {
|
while (clazz != null) {
|
||||||
struct = definition.classes.get(clazz);
|
Struct struct = definition.classes.get(clazz);
|
||||||
|
|
||||||
if (struct != null) {
|
if (struct != null) {
|
||||||
field = struct.members.get(name);
|
Field field = struct.members.get(name);
|
||||||
|
|
||||||
if (field != null) {
|
if (field != null) {
|
||||||
break;
|
return field;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -307,30 +291,18 @@ public class Def {
|
||||||
struct = definition.classes.get(iface);
|
struct = definition.classes.get(iface);
|
||||||
|
|
||||||
if (struct != null) {
|
if (struct != null) {
|
||||||
field = struct.members.get(name);
|
Field field = struct.members.get(name);
|
||||||
|
|
||||||
if (field != null) {
|
if (field != null) {
|
||||||
break;
|
return field;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (struct != null) {
|
|
||||||
field = struct.members.get(name);
|
|
||||||
|
|
||||||
if (field != null) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
clazz = clazz.getSuperclass();
|
clazz = clazz.getSuperclass();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (struct == null) {
|
return null;
|
||||||
throw new IllegalArgumentException("Unable to find a dynamic struct for class [" + owner.getClass() + "].");
|
|
||||||
}
|
|
||||||
|
|
||||||
return field;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Transform getTransform(Class<?> fromClass, Class<?> toClass, final Definition definition) {
|
public static Transform getTransform(Class<?> fromClass, Class<?> toClass, final Definition definition) {
|
||||||
|
|
Loading…
Reference in New Issue