From 38fc8125e2728926da31555386b93a0d5acb1c0e Mon Sep 17 00:00:00 2001 From: Joe Guo Date: Thu, 10 May 2018 17:11:29 +1200 Subject: [PATCH] traffic: improve is_really_a_packet This function will repeat on each packet. Avoid exception for getattr, which is expensive for performance. Signed-off-by: Joe Guo Reviewed-by: Andrew Bartlett Reviewed-by: Garming Sam --- python/samba/emulate/traffic.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/python/samba/emulate/traffic.py b/python/samba/emulate/traffic.py index 08a0fa32278..503e1e4c5bf 100644 --- a/python/samba/emulate/traffic.py +++ b/python/samba/emulate/traffic.py @@ -273,13 +273,12 @@ class Packet(object): return False fn_name = 'packet_%s_%s' % (self.protocol, self.opcode) - try: - fn = getattr(traffic_packets, fn_name) - if fn is traffic_packets.null_packet: - return False - except AttributeError: + fn = getattr(traffic_packets, fn_name, None) + if not fn: print("missing packet %s" % fn_name, file=sys.stderr) return False + if fn is traffic_packets.null_packet: + return False return True