From d4910d9edcbe1f72c08a378aabe1e6e2e2d46999 Mon Sep 17 00:00:00 2001 From: Andrew Steinborn Date: Thu, 27 Sep 2018 02:37:53 -0400 Subject: [PATCH] Remove potentially high-frequency usages of streams --- .../proxy/command/VelocityCommandManager.java | 13 ++++++++----- .../proxy/messages/VelocityChannelRegistrar.java | 10 ++++++---- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/proxy/src/main/java/com/velocitypowered/proxy/command/VelocityCommandManager.java b/proxy/src/main/java/com/velocitypowered/proxy/command/VelocityCommandManager.java index 1b952e1dd..0f2961910 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/command/VelocityCommandManager.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/command/VelocityCommandManager.java @@ -68,11 +68,14 @@ public class VelocityCommandManager implements CommandManager { String alias = split[0]; if (split.length == 1) { - return Optional.of(commands.entrySet().stream() - .filter(ent -> ent.getKey().regionMatches(true, 0, alias, 0, alias.length())) - .filter(ent -> ent.getValue().hasPermission(source, new String[0])) - .map(ent -> "/" + ent.getKey()) - .collect(Collectors.toList())); + List availableCommands = new ArrayList<>(); + for (Map.Entry entry : commands.entrySet()) { + if (entry.getKey().regionMatches(true, 0, alias, 0, alias.length()) && + entry.getValue().hasPermission(source, new String[0])) { + availableCommands.add("/" + entry.getKey()); + } + } + return Optional.of(availableCommands); } String[] actualArgs = Arrays.copyOfRange(split, 1, split.length); diff --git a/proxy/src/main/java/com/velocitypowered/proxy/messages/VelocityChannelRegistrar.java b/proxy/src/main/java/com/velocitypowered/proxy/messages/VelocityChannelRegistrar.java index c6feff212..435d0ec42 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/messages/VelocityChannelRegistrar.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/messages/VelocityChannelRegistrar.java @@ -7,6 +7,7 @@ import com.velocitypowered.api.proxy.messages.ChannelRegistrar; import com.velocitypowered.api.proxy.messages.LegacyChannelIdentifier; import com.velocitypowered.api.proxy.messages.MinecraftChannelIdentifier; +import java.util.ArrayList; import java.util.Collection; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; @@ -44,10 +45,11 @@ public class VelocityChannelRegistrar implements ChannelRegistrar { } public Collection getModernChannelIds() { - return identifierMap.values().stream() - .filter(i -> i instanceof MinecraftChannelIdentifier) - .map(ChannelIdentifier::getId) - .collect(Collectors.toList()); + Collection ids = new ArrayList<>(); + for (ChannelIdentifier value : identifierMap.values()) { + ids.add(value.getId()); + } + return ids; } public boolean registered(String id) {