Warn about EventNode#map performance

This commit is contained in:
TheMode 2021-08-22 00:41:30 +02:00
parent d9c000f80a
commit 6f88abf987
2 changed files with 16 additions and 2 deletions

View File

@ -352,9 +352,24 @@ public interface EventNode<T extends Event> {
@Contract(value = "_ -> this")
@NotNull EventNode<T> removeListener(@NotNull EventListener<? extends T> listener);
/**
* Maps a specific object to a node.
* <p>
* Be aware that such structure have huge performance penalty as they will
* always require a map lookup. Use only at last resort.
*
* @param node the node to map
* @param value the mapped value
*/
@ApiStatus.Experimental
void map(@NotNull EventNode<? extends T> node, @NotNull Object value);
/**
* Undo {@link #map(EventNode, Object)}
*
* @param value the value to unmap
* @return true if the value has been unmapped, false if nothing happened
*/
@ApiStatus.Experimental
boolean unmap(@NotNull Object value);

View File

@ -326,8 +326,7 @@ class EventNodeImpl<T extends Event> implements EventNode<T> {
// Retrieve all filters used to retrieve potential handlers
for (var mappedEntry : mappedNodeCache.entrySet()) {
final EventNodeImpl<E> mappedNode = mappedEntry.getValue();
final Class<E> mappedNodeType = mappedNode.eventType;
if (!mappedNodeType.isAssignableFrom(eventType)) continue;
if (!mappedNode.eventType.isAssignableFrom(eventType)) continue;
if (mappedNode.listenerMap.isEmpty())
continue; // The mapped node does not have any listener (perhaps throw a warning?)
filters.add(mappedNode.filter);