This commit is contained in:
parent
55b30e02c2
commit
af2c043bab
2 changed files with 1 additions and 10 deletions
|
@ -18,8 +18,6 @@ public class DarkField {
|
||||||
public static Field nameToField(Class<?> owner, String name) {
|
public static Field nameToField(Class<?> owner, String name) {
|
||||||
try {
|
try {
|
||||||
// try the basic strategy first - it works often enough for this to be a speed advantage.
|
// try the basic strategy first - it works often enough for this to be a speed advantage.
|
||||||
// this also prevents a StackOverflowError if we're using a ReflectionDataClass with a
|
|
||||||
// BasicOffsetGetter (like on some non-openjdk jvms)
|
|
||||||
return owner.getDeclaredField(name);
|
return owner.getDeclaredField(name);
|
||||||
} catch (NoSuchFieldException e) {
|
} catch (NoSuchFieldException e) {
|
||||||
return Arrays.stream(Strategy.classStrategy.instance(owner).getDeclaredFields()).filter(x -> x.getName().equals(name)).findAny().orElse(null);
|
return Arrays.stream(Strategy.classStrategy.instance(owner).getDeclaredFields()).filter(x -> x.getName().equals(name)).findAny().orElse(null);
|
||||||
|
|
|
@ -14,7 +14,6 @@ import static de.tudbut.darkreflection.UnsafeProvider.offsetGetter;
|
||||||
|
|
||||||
|
|
||||||
// which strategy depends on which?
|
// which strategy depends on which?
|
||||||
// FReflectionDataClass -> reflectionFieldStrategy
|
|
||||||
// FieldByName -> reflectedFieldStrategy
|
// FieldByName -> reflectedFieldStrategy
|
||||||
// FieldByName -> classStrategy
|
// FieldByName -> classStrategy
|
||||||
|
|
||||||
|
@ -116,13 +115,7 @@ public class Strategy {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
DarkReflection((owner, field, isStatic, type) -> {
|
DarkReflection((owner, field, isStatic, type) -> reflectedFieldStrategy.instance(Arrays.stream(classStrategy.instance(owner).getDeclaredFields()).filter(x -> x.getName().equals(field)).findAny().orElse(null))),
|
||||||
try {
|
|
||||||
return reflectedFieldStrategy.instance(Arrays.stream(classStrategy.instance(owner).getDeclaredFields()).filter(x -> x.getName().equals(field)).findAny().orElseThrow(() -> new NoSuchFieldException(field)));
|
|
||||||
} catch (NoSuchFieldException e) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}),
|
|
||||||
Unsafe((owner, field, isStatic, type) -> new UnsafeField<>(
|
Unsafe((owner, field, isStatic, type) -> new UnsafeField<>(
|
||||||
isStatic ? offsetGetter.staticFieldBase(owner, field) : null,
|
isStatic ? offsetGetter.staticFieldBase(owner, field) : null,
|
||||||
isStatic ? offsetGetter.staticFieldOffset(owner, field) : offsetGetter.objectFieldOffset(owner, field), type)),
|
isStatic ? offsetGetter.staticFieldOffset(owner, field) : offsetGetter.objectFieldOffset(owner, field), type)),
|
||||||
|
|
Loading…
Add table
Reference in a new issue