Remove unnecessary code in EventBus

This commit is contained in:
Vankka 2022-03-28 17:34:16 +03:00
parent 29e01878b2
commit 627ec3045c
No known key found for this signature in database
GPG Key ID: 6E50CB7A29B96AD0

View File

@ -75,12 +75,11 @@ public class EventBusImpl implements EventBus {
List<Throwable> suppressedMethods = new ArrayList<>(); List<Throwable> suppressedMethods = new ArrayList<>();
List<EventListenerImpl> methods = new ArrayList<>(); List<EventListenerImpl> methods = new ArrayList<>();
EnumMap<EventPriority, List<EventListenerImpl>> methodsByPriority = new EnumMap<>(EventPriority.class);
Class<?> currentClass = listenerClass; Class<?> currentClass = listenerClass;
do { do {
for (Method method : currentClass.getDeclaredMethods()) { for (Method method : currentClass.getDeclaredMethods()) {
checkMethod(eventListener, listenerClass, method, suppressedMethods, methods, methodsByPriority); checkMethod(eventListener, listenerClass, method, suppressedMethods, methods);
} }
} while ((currentClass = currentClass.getSuperclass()) != null); } while ((currentClass = currentClass.getSuperclass()) != null);
@ -97,8 +96,7 @@ public class EventBusImpl implements EventBus {
} }
private void checkMethod(Object eventListener, Class<?> listenerClass, Method method, private void checkMethod(Object eventListener, Class<?> listenerClass, Method method,
List<Throwable> suppressedMethods, List<EventListenerImpl> methods, List<Throwable> suppressedMethods, List<EventListenerImpl> methods) {
EnumMap<EventPriority, List<EventListenerImpl>> methodsByPriority) {
Subscribe annotation = method.getAnnotation(Subscribe.class); Subscribe annotation = method.getAnnotation(Subscribe.class);
if (annotation == null) { if (annotation == null) {
return; return;
@ -144,12 +142,8 @@ public class EventBusImpl implements EventBus {
return; return;
} }
EventPriority eventPriority = annotation.priority();
EventListenerImpl listener = new EventListenerImpl(eventListener, listenerClass, annotation, firstParameter, method); EventListenerImpl listener = new EventListenerImpl(eventListener, listenerClass, annotation, firstParameter, method);
methods.add(listener); methods.add(listener);
methodsByPriority.computeIfAbsent(eventPriority, key -> new CopyOnWriteArrayList<>())
.add(listener);
} }
private Throwable createReasonException(String message) { private Throwable createReasonException(String message) {