mirror of
https://github.com/dmulloy2/ProtocolLib.git
synced 2024-12-17 22:57:51 +01:00
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:
parent
b04fca8324
commit
944b3f8280
@ -654,6 +654,7 @@ public class PacketType implements Serializable, Cloneable, Comparable<PacketTyp
|
|||||||
private boolean forceAsync;
|
private boolean forceAsync;
|
||||||
|
|
||||||
private boolean dynamic;
|
private boolean dynamic;
|
||||||
|
private int hashCode;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve the current packet/legacy lookup.
|
* Retrieve the current packet/legacy lookup.
|
||||||
@ -1191,7 +1192,14 @@ public class PacketType implements Serializable, Cloneable, Comparable<PacketTyp
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
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
|
@Override
|
||||||
|
Loading…
Reference in New Issue
Block a user