Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't sort children on node addition to save on performance #68

Merged
merged 2 commits into from
Mar 18, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions src/main/java/com/mojang/brigadier/tree/CommandNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;
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 TreeMap<>();
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;
Expand Down Expand Up @@ -88,8 +88,6 @@ public void addChild(final CommandNode<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));
aikar marked this conversation as resolved.
Show resolved Hide resolved
}

public void findAmbiguities(final AmbiguityConsumer<S> consumer) {
Expand Down