Use Fastutil

This commit is contained in:
Camotoy 2022-06-04 10:05:39 -04:00
parent 8b4a2aaac8
commit dfb471df99
No known key found for this signature in database
GPG key ID: 7EEFB66FE798081F
2 changed files with 16 additions and 7 deletions

View file

@ -91,6 +91,13 @@
<groupId>com.github.spotbugs</groupId> <groupId>com.github.spotbugs</groupId>
<artifactId>spotbugs-annotations</artifactId> <artifactId>spotbugs-annotations</artifactId>
<version>4.3.0</version> <version>4.3.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.nukkitx.fastutil</groupId>
<artifactId>fastutil-int-object-maps</artifactId>
<version>8.5.2</version>
<scope>compile</scope>
</dependency> </dependency>
</dependencies> </dependencies>

View file

@ -6,6 +6,8 @@ import com.github.steveice10.packetlib.codec.PacketCodecHelper;
import com.github.steveice10.packetlib.codec.PacketDefinition; import com.github.steveice10.packetlib.codec.PacketDefinition;
import com.github.steveice10.packetlib.codec.PacketSerializer; import com.github.steveice10.packetlib.codec.PacketSerializer;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
import java.io.IOException; import java.io.IOException;
import java.util.HashMap; import java.util.HashMap;
@ -17,8 +19,8 @@ import java.util.Map;
* All implementations must have a constructor that takes in a {@link ByteBuf}. * All implementations must have a constructor that takes in a {@link ByteBuf}.
*/ */
public abstract class PacketProtocol { public abstract class PacketProtocol {
private final Map<Integer, PacketDefinition<? extends Packet, ?>> serverbound = new HashMap<>(); private final Int2ObjectMap<PacketDefinition<? extends Packet, ?>> serverbound = new Int2ObjectOpenHashMap<>();
private final Map<Integer, PacketDefinition<? extends Packet, ?>> clientbound = new HashMap<>(); private final Int2ObjectMap<PacketDefinition<? extends Packet, ?>> clientbound = new Int2ObjectOpenHashMap<>();
private final Map<Class<? extends Packet>, Integer> clientboundIds = new IdentityHashMap<>(); private final Map<Class<? extends Packet>, Integer> clientboundIds = new IdentityHashMap<>();
private final Map<Class<? extends Packet>, Integer> serverboundIds = new IdentityHashMap<>(); private final Map<Class<? extends Packet>, Integer> serverboundIds = new IdentityHashMap<>();