Cache PacketType#hashCode (#818)

This should result in a general performance improvement, as PacketType is often used as map keys across ProtocolLib.
This commit is contained in:
Andrew Steinborn 2020-05-24 15:45:42 -04:00 committed by GitHub
parent b04fca8324
commit 944b3f8280
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 9 additions and 1 deletions

View File

@ -654,6 +654,7 @@ public class PacketType implements Serializable, Cloneable, Comparable<PacketTyp
private boolean forceAsync;
private boolean dynamic;
private int hashCode;
/**
* Retrieve the current packet/legacy lookup.
@ -1191,7 +1192,14 @@ public class PacketType implements Serializable, Cloneable, Comparable<PacketTyp
@Override
public int hashCode() {
return Objects.hashCode(protocol, sender, currentId);
int hash = hashCode;
if (hash == 0) {
hash = protocol.hashCode();
hash = 31 * hash + sender.hashCode();
hash = 31 * hash + Integer.hashCode(currentId);
hashCode = hash;
}
return hash;
}
@Override