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 dda9680be5
Co-authored-by: virustotalop <virustotalop@gmail.com>
* Restore back to a LinkedHashMap
since iteration order isn't important anyways.
Co-authored-by: virustotalop <virustotalop@gmail.com>
This commit is contained in:
parent
55f6e25c03
commit
242de3fe73
1 changed files with 3 additions and 6 deletions
|
@ -22,12 +22,11 @@ import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
import java.util.function.Predicate;
|
import java.util.function.Predicate;
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
public abstract class CommandNode<S> implements Comparable<CommandNode<S>> {
|
public abstract class CommandNode<S> implements Comparable<CommandNode<S>> {
|
||||||
private Map<String, CommandNode<S>> children = new LinkedHashMap<>();
|
private final Map<String, CommandNode<S>> children = new LinkedHashMap<>();
|
||||||
private Map<String, LiteralCommandNode<S>> literals = new LinkedHashMap<>();
|
private final Map<String, LiteralCommandNode<S>> literals = new LinkedHashMap<>();
|
||||||
private Map<String, ArgumentCommandNode<S, ?>> arguments = new LinkedHashMap<>();
|
private final Map<String, ArgumentCommandNode<S, ?>> arguments = new LinkedHashMap<>();
|
||||||
private final Predicate<S> requirement;
|
private final Predicate<S> requirement;
|
||||||
private final CommandNode<S> redirect;
|
private final CommandNode<S> redirect;
|
||||||
private final RedirectModifier<S> modifier;
|
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);
|
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) {
|
public void findAmbiguities(final AmbiguityConsumer<S> consumer) {
|
||||||
|
|
Loading…
Reference in a new issue