mirror of
https://github.com/ViaVersion/ViaVersion.git
synced 2024-11-05 18:20:17 +01:00
Optimize packet searching
This commit is contained in:
parent
3511f9a7b2
commit
afe18379e0
@ -172,11 +172,11 @@ public enum PacketType {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static PacketType findNewPacket(State state, Direction direction, int id) {
|
public static PacketType findNewPacket(State state, Direction direction, int id) {
|
||||||
return newids.get(toLong((short)direction.ordinal(), (short) state.ordinal(), id));
|
return newids.get(toShort((short) id, (short)direction.ordinal(), (short) state.ordinal()));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static PacketType findOldPacket(State state, Direction direction, int id) {
|
public static PacketType findOldPacket(State state, Direction direction, int id) {
|
||||||
return oldids.get(toLong((short)direction.ordinal(), (short) state.ordinal(), id));
|
return oldids.get(toShort((short) id, (short)direction.ordinal(), (short) state.ordinal()));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static PacketType getIncomingPacket(State state, int id) {
|
public static PacketType getIncomingPacket(State state, int id) {
|
||||||
@ -187,17 +187,16 @@ public enum PacketType {
|
|||||||
return findOldPacket(state, Direction.OUTGOING, id);
|
return findOldPacket(state, Direction.OUTGOING, id);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static long toLong(short a, short b, int c) {
|
private static short toShort(short id, short direction, short state) {
|
||||||
int d = (a << 16) | (b & 0xFFFF);
|
return (short) ((id & 0x00FF) | (direction<<8) & 0x0F00 | (state << 12) & 0xF000);
|
||||||
return (long) c << 32 | d & 0xFFFFFFFFL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static HashMap<Long, PacketType> oldids = new HashMap<Long, PacketType>();
|
private static HashMap<Short, PacketType> oldids = new HashMap<Short, PacketType>();
|
||||||
private static HashMap<Long, PacketType> newids = new HashMap<Long, PacketType>();
|
private static HashMap<Short, PacketType> newids = new HashMap<Short, PacketType>();
|
||||||
static {
|
static {
|
||||||
for(PacketType pt : PacketType.values()) {
|
for(PacketType pt : PacketType.values()) {
|
||||||
oldids.put(toLong((short)pt.getDirection().ordinal(), (short)pt.getState().ordinal(), pt.getPacketID()), pt);
|
oldids.put(toShort((short) pt.getPacketID(), (short)pt.getDirection().ordinal(), (short)pt.getState().ordinal()), pt);
|
||||||
newids.put(toLong((short)pt.getDirection().ordinal(), (short)pt.getState().ordinal(), pt.getNewPacketID()), pt);
|
newids.put(toShort((short) pt.getNewPacketID(), (short)pt.getDirection().ordinal(), (short)pt.getState().ordinal()), pt);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user