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

17
pom.xml
View file

@ -87,11 +87,18 @@
<version>0.0.8.Final</version>
<classifier>linux-x86_64</classifier>
</dependency>
<dependency>
<groupId>com.github.spotbugs</groupId>
<artifactId>spotbugs-annotations</artifactId>
<version>4.3.0</version>
</dependency>
<dependency>
<groupId>com.github.spotbugs</groupId>
<artifactId>spotbugs-annotations</artifactId>
<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>
</dependencies>
<build>

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.PacketSerializer;
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.util.HashMap;
@ -17,8 +19,8 @@ import java.util.Map;
* All implementations must have a constructor that takes in a {@link ByteBuf}.
*/
public abstract class PacketProtocol {
private final Map<Integer, PacketDefinition<? extends Packet, ?>> serverbound = new HashMap<>();
private final Map<Integer, PacketDefinition<? extends Packet, ?>> clientbound = new HashMap<>();
private final Int2ObjectMap<PacketDefinition<? extends Packet, ?>> serverbound = new Int2ObjectOpenHashMap<>();
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> serverboundIds = new IdentityHashMap<>();