Skip to content

Commit 944b3f8

Browse files
authored
Cache PacketType#hashCode (#818)
This should result in a general performance improvement, as PacketType is often used as map keys across ProtocolLib.
1 parent b04fca8 commit 944b3f8

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/main/java/com/comphenix/protocol/PacketType.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -654,6 +654,7 @@ public String getPacketName() {
654654
private boolean forceAsync;
655655

656656
private boolean dynamic;
657+
private int hashCode;
657658

658659
/**
659660
* Retrieve the current packet/legacy lookup.
@@ -1191,7 +1192,14 @@ public boolean isDynamic() {
11911192

11921193
@Override
11931194
public int hashCode() {
1194-
return Objects.hashCode(protocol, sender, currentId);
1195+
int hash = hashCode;
1196+
if (hash == 0) {
1197+
hash = protocol.hashCode();
1198+
hash = 31 * hash + sender.hashCode();
1199+
hash = 31 * hash + Integer.hashCode(currentId);
1200+
hashCode = hash;
1201+
}
1202+
return hash;
11951203
}
11961204

11971205
@Override

0 commit comments

Comments
 (0)