Don't sort children on node addition to save on performance (#68)
* Use a Tree Map for children to save on performance Everytime a child is added to the CommandNode, the children was sorted. This action is extremely heavy with large node trees such as Minecraft. From what I can see, sort order was not even needed by type since the dispatcher parse checks argument and literal nodes instead. Testing on /bossbar command seemed to have no impact to behavior. Credit to https://github.com/PaperMC/Paper/commit/dda9680be520bba8cc8b4a20072af42bd8420e7a Co-authored-by: virustotalop <[email protected]> * Restore back to a LinkedHashMap since iteration order isn't important anyways. Co-authored-by: virustotalop <[email protected]>
This commit is contained in:
co-authored by
virustotalop
parent
55f6e25c03
commit
242de3fe73
@@ -22,12 +22,11 @@ import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public abstract class CommandNode<S> implements Comparable<CommandNode<S>> {
|
||||
private Map<String, CommandNode<S>> children = new LinkedHashMap<>();
|
||||
private Map<String, LiteralCommandNode<S>> literals = new LinkedHashMap<>();
|
||||
private Map<String, ArgumentCommandNode<S, ?>> arguments = new LinkedHashMap<>();
|
||||
private final Map<String, CommandNode<S>> children = new LinkedHashMap<>();
|
||||
private final Map<String, LiteralCommandNode<S>> literals = new LinkedHashMap<>();
|
||||
private final Map<String, ArgumentCommandNode<S, ?>> arguments = new LinkedHashMap<>();
|
||||
private final Predicate<S> requirement;
|
||||
private final CommandNode<S> redirect;
|
||||
private final RedirectModifier<S> modifier;
|
||||
@@ -88,8 +87,6 @@ public abstract class CommandNode<S> implements Comparable<CommandNode<S>> {
|
||||
arguments.put(node.getName(), (ArgumentCommandNode<S, ?>) node);
|
||||
}
|
||||
}
|
||||
|
||||
children = children.entrySet().stream().sorted(Map.Entry.comparingByValue()).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue, (e1, e2) -> e1, LinkedHashMap::new));
|
||||
}
|
||||
|
||||
public void findAmbiguities(final AmbiguityConsumer<S> consumer) {
|
||||
|
||||
Reference in New Issue
Block a user