mirror of
https://github.com/Minestom/Minestom.git
synced 2025-01-02 14:38:26 +01:00
Warn about EventNode#map performance
This commit is contained in:
parent
d9c000f80a
commit
6f88abf987
@ -352,9 +352,24 @@ public interface EventNode<T extends Event> {
|
|||||||
@Contract(value = "_ -> this")
|
@Contract(value = "_ -> this")
|
||||||
@NotNull EventNode<T> removeListener(@NotNull EventListener<? extends T> listener);
|
@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
|
@ApiStatus.Experimental
|
||||||
void map(@NotNull EventNode<? extends T> node, @NotNull Object value);
|
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
|
@ApiStatus.Experimental
|
||||||
boolean unmap(@NotNull Object value);
|
boolean unmap(@NotNull Object value);
|
||||||
|
|
||||||
|
@ -326,8 +326,7 @@ class EventNodeImpl<T extends Event> implements EventNode<T> {
|
|||||||
// Retrieve all filters used to retrieve potential handlers
|
// Retrieve all filters used to retrieve potential handlers
|
||||||
for (var mappedEntry : mappedNodeCache.entrySet()) {
|
for (var mappedEntry : mappedNodeCache.entrySet()) {
|
||||||
final EventNodeImpl<E> mappedNode = mappedEntry.getValue();
|
final EventNodeImpl<E> mappedNode = mappedEntry.getValue();
|
||||||
final Class<E> mappedNodeType = mappedNode.eventType;
|
if (!mappedNode.eventType.isAssignableFrom(eventType)) continue;
|
||||||
if (!mappedNodeType.isAssignableFrom(eventType)) continue;
|
|
||||||
if (mappedNode.listenerMap.isEmpty())
|
if (mappedNode.listenerMap.isEmpty())
|
||||||
continue; // The mapped node does not have any listener (perhaps throw a warning?)
|
continue; // The mapped node does not have any listener (perhaps throw a warning?)
|
||||||
filters.add(mappedNode.filter);
|
filters.add(mappedNode.filter);
|
||||||
|
Loading…
Reference in New Issue
Block a user