From: Joe Guo Date: Thu, 10 May 2018 05:23:02 +0000 (+1200) Subject: traffic: improve add_short_packet by avoiding dict.get X-Git-Url: http://git.samba.org/?p=metze%2Fsamba%2Fwip.git;a=commitdiff_plain;h=d444221d67abc05dc9966dd7e0a37d30f9848953 traffic: improve add_short_packet by avoiding dict.get dict.get is slower than []. Avoid get to improve performance. (For 3989418 calls, total time decease from 9.395 to 8.573) Signed-off-by: Joe Guo Reviewed-by: Andrew Bartlett Reviewed-by: Garming Sam Autobuild-User(master): Andrew Bartlett Autobuild-Date(master): Mon May 14 05:38:06 CEST 2018 on sn-devel-144 --- diff --git a/python/samba/emulate/traffic.py b/python/samba/emulate/traffic.py index 227477a5425c..db0fcf7788bd 100644 --- a/python/samba/emulate/traffic.py +++ b/python/samba/emulate/traffic.py @@ -811,9 +811,12 @@ class Conversation(object): src, dest = self.guess_client_server() if not client: src, dest = dest, src - - desc = OP_DESCRIPTIONS.get((protocol, opcode), '') - ip_protocol = IP_PROTOCOLS.get(protocol, '06') + key = (protocol, opcode) + desc = OP_DESCRIPTIONS[key] if key in OP_DESCRIPTIONS else '' + if protocol in IP_PROTOCOLS: + ip_protocol = IP_PROTOCOLS[protocol] + else: + ip_protocol = '06' packet = Packet(timestamp - self.start_time, ip_protocol, '', src, dest, protocol, opcode, desc, extra)