- Joined
- Jun 5, 2010
- Messages
- 567
- Reaction score
- 598
Why is it that the system odinms had with the packet handlers is changed to iterate through the enums? It was a map before and it should run faster. Selecting from a hashmap should have on average constant time, while selecting with switch is at best linear time, and it is being looped from all the enums on top of that before even selecting. If there were 10 opcodes, MAYBE hashmap would be slower.
Haven't looked into java for a while but I believe for each works like this:
which should not be faster.
Also, commands are cached using maps. Items and data are cached using maps. Why are packet handlers the only thing that aren't?
This is the odinms implementation:
This is the celino implementation:
Haven't looked into java for a while but I believe for each works like this:
Code:
for (RecvPacketOpcode op : RecvPacketOpcode.values()) {
...
}
Code:
Iterator<RecvPacketOpcode> it = RecvPacketOpcode.values().iterator();
while (it.hasNext()) {
RecvPacketOpcode op = (RecvPacketOpcode) it.next();
...
it.remove();
}
Also, commands are cached using maps. Items and data are cached using maps. Why are packet handlers the only thing that aren't?
This is the odinms implementation:
Code:
if (map.containsKey(packetHeader)) handlePacket
This is the celino implementation:
Code:
for (RecvOpcode r : opcodes) {
if (r.getValue() == packetHeader) {
handlePacket(opcode)
break;
}
}
...
void handlePacket(packetHeader)
switch (packetHeader) {
case 1: handlePacket
...
case 200: handlePacket
}
Last edited: