Skip to content

Commit 2c7c60a

Browse files
authored
Major performance improvements
Replaced byte string concatenation with bytearray extend functions. This is ~50 times faster! (See also #8)
1 parent 6852d3c commit 2c7c60a

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

vxi11/rpc.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -232,21 +232,20 @@ def recvfrag(sock):
232232
x = struct.unpack(">I", header[0:4])[0]
233233
last = ((x & 0x80000000) != 0)
234234
n = int(x & 0x7fffffff)
235-
frag = b''
236-
while n > 0:
237-
buf = sock.recv(n)
235+
frag = bytearray()
236+
while len(frag) < n:
237+
buf = sock.recv(n - len(frag))
238238
if not buf: raise EOFError
239-
n = n - len(buf)
240-
frag = frag + buf
239+
frag.extend(buf)
241240
return last, frag
242241

243242
def recvrecord(sock):
244-
record = b''
243+
record = bytearray()
245244
last = 0
246245
while not last:
247246
last, frag = recvfrag(sock)
248-
record = record + frag
249-
return record
247+
record.extend(frag)
248+
return bytes(record)
250249

251250

252251
# Client using TCP to a specific port

0 commit comments

Comments
 (0)