traffic: improve add_short_packet by avoiding str.split
authorJoe Guo <joeg@catalyst.net.nz>
Thu, 10 May 2018 05:04:50 +0000 (17:04 +1200)
committerAndrew Bartlett <abartlet@samba.org>
Sat, 12 May 2018 00:09:29 +0000 (02:09 +0200)
Avoid str.split, which will repeat for each packet.

Signed-off-by: Joe Guo <joeg@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
Reviewed-by: Garming Sam <garming@catalyst.net.nz>
python/samba/emulate/traffic.py

index 95ab3c9d380a3f60600ad3ee177f56653a8f4d30..08a0fa3227862f8bc9466b0092a93adf934a8097 100644 (file)
@@ -794,12 +794,12 @@ class Conversation(object):
         if p.is_really_a_packet():
             self.packets.append(p)
 
-    def add_short_packet(self, timestamp, p, extra, client=True):
+    def add_short_packet(self, timestamp, protocol, opcode, extra,
+                         client=True):
         """Create a packet from a timestamp, and 'protocol:opcode' pair, and a
         (possibly empty) list of extra data. If client is True, assume
         this packet is from the client to the server.
         """
-        protocol, opcode = p.split(':', 1)
         src, dest = self.guess_client_server()
         if not client:
             src, dest = dest, src
@@ -1220,7 +1220,7 @@ class TrafficModel(object):
                 timestamp += wait
                 if hard_stop is not None and timestamp > hard_stop:
                     break
-                c.add_short_packet(timestamp, p, extra)
+                c.add_short_packet(timestamp, protocol, opcode, extra)
 
             key = key[1:] + (p,)