use fastutil's Object2IntOpenHashMap

This commit is contained in:
kashike
2018-08-10 18:32:27 -07:00
parent 8998bc7c8f
commit e9959f81fb
2 changed files with 49 additions and 3 deletions

View File

@@ -4,6 +4,8 @@ import com.google.common.primitives.ImmutableIntArray;
import com.velocitypowered.proxy.protocol.packet.*;
import io.netty.util.collection.IntObjectHashMap;
import io.netty.util.collection.IntObjectMap;
import it.unimi.dsi.fastutil.objects.Object2IntMap;
import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap;
import java.util.*;
import java.util.function.Supplier;
@@ -217,10 +219,11 @@ public enum StateRegistry {
public class ProtocolVersion {
public final int id;
final IntObjectMap<Supplier<? extends MinecraftPacket>> packetIdToSupplier = new IntObjectHashMap<>(16, 0.5f);
final Map<Class<? extends MinecraftPacket>, Integer> packetClassToId = new HashMap<>(16, 0.5f);
final Object2IntMap<Class<? extends MinecraftPacket>> packetClassToId = new Object2IntOpenHashMap<>(16, 0.5f);
ProtocolVersion(final int id) {
this.id = id;
this.packetClassToId.defaultReturnValue(Integer.MIN_VALUE);
}
public MinecraftPacket createPacket(final int id) {
@@ -232,8 +235,8 @@ public enum StateRegistry {
}
public int getPacketId(final MinecraftPacket packet) {
final Integer id = this.packetClassToId.get(packet.getClass());
if (id == null) {
final int id = this.packetClassToId.getInt(packet.getClass());
if (id == Integer.MIN_VALUE) {
throw new IllegalArgumentException(String.format(
"Unable to find id for packet of type %s in %s protocol %s",
packet.getClass().getName(), PacketRegistry.this.direction, this.id