Skip to content

Commit 1699128

Browse files
author
Ma Lin
authored
GH-91355: micro-optimize Connection.send_bytes() method (gh-32247)
1 parent 9dc4aae commit 1699128

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

Lib/multiprocessing/connection.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -188,10 +188,9 @@ def send_bytes(self, buf, offset=0, size=None):
188188
self._check_closed()
189189
self._check_writable()
190190
m = memoryview(buf)
191-
# HACK for byte-indexing of non-bytewise buffers (e.g. array.array)
192191
if m.itemsize > 1:
193-
m = memoryview(bytes(m))
194-
n = len(m)
192+
m = m.cast('B')
193+
n = m.nbytes
195194
if offset < 0:
196195
raise ValueError("offset is negative")
197196
if n < offset:

0 commit comments

Comments
 (0)