13
0
geforkt von Mirrors/Velocity

We don't need the sorted order that a List provides

Dieser Commit ist enthalten in:
Andrew Steinborn 2021-07-19 13:33:03 -04:00
Ursprung 349781cff8
Commit 2f82603f65
2 geänderte Dateien mit 12 neuen und 10 gelöschten Zeilen

Datei anzeigen

@ -17,27 +17,28 @@
package com.velocitypowered.proxy.event; package com.velocitypowered.proxy.event;
import com.google.common.collect.ArrayListMultimap; import com.google.common.collect.HashMultimap;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import com.google.common.collect.ListMultimap; import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Multimap;
import com.google.common.reflect.TypeToken; import com.google.common.reflect.TypeToken;
import java.util.List; import java.util.Collection;
import java.util.stream.Collectors; import java.util.stream.Collectors;
class EventTypeTracker { class EventTypeTracker {
private final ListMultimap<Class<?>, Class<?>> friends; private final Multimap<Class<?>, Class<?>> friends;
public EventTypeTracker() { public EventTypeTracker() {
this.friends = ArrayListMultimap.create(); this.friends = HashMultimap.create();
} }
public List<Class<?>> getFriendsOf(final Class<?> eventType) { public Collection<Class<?>> getFriendsOf(final Class<?> eventType) {
if (friends.containsKey(eventType)) { if (friends.containsKey(eventType)) {
return ImmutableList.copyOf(friends.get(eventType)); return ImmutableSet.copyOf(friends.get(eventType));
} }
final List<Class<?>> types = getEventTypes(eventType); final Collection<Class<?>> types = getEventTypes(eventType);
for (Class<?> type : types) { for (Class<?> type : types) {
if (type == eventType) { if (type == eventType) {
continue; continue;
@ -48,7 +49,7 @@ class EventTypeTracker {
return types; return types;
} }
private static List<Class<?>> getEventTypes(final Class<?> eventType) { private static Collection<Class<?>> getEventTypes(final Class<?> eventType) {
return TypeToken.of(eventType).getTypes().rawTypes().stream() return TypeToken.of(eventType).getTypes().rawTypes().stream()
.filter(type -> type != Object.class) .filter(type -> type != Object.class)
.collect(Collectors.toList()); .collect(Collectors.toList());

Datei anzeigen

@ -46,6 +46,7 @@ import java.lang.reflect.Method;
import java.lang.reflect.Modifier; import java.lang.reflect.Modifier;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.Comparator; import java.util.Comparator;
import java.util.HashMap; import java.util.HashMap;
@ -175,7 +176,7 @@ public class VelocityEventManager implements EventManager {
private @Nullable HandlersCache bakeHandlers(final Class<?> eventType) { private @Nullable HandlersCache bakeHandlers(final Class<?> eventType) {
final List<HandlerRegistration> baked = new ArrayList<>(); final List<HandlerRegistration> baked = new ArrayList<>();
final List<Class<?>> types = eventTypeTracker.getFriendsOf(eventType); final Collection<Class<?>> types = eventTypeTracker.getFriendsOf(eventType);
lock.readLock().lock(); lock.readLock().lock();
try { try {