GH-91355: micro-optimize Connection.send_bytes() method (gh-32247)

This commit is contained in:
Ma Lin 2022-05-03 22:41:45 +08:00 committed by GitHub
parent 9dc4aae8e9
commit 1699128c48
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -188,10 +188,9 @@ class _ConnectionBase:
self._check_closed()
self._check_writable()
m = memoryview(buf)
# HACK for byte-indexing of non-bytewise buffers (e.g. array.array)
if m.itemsize > 1:
m = memoryview(bytes(m))
n = len(m)
m = m.cast('B')
n = m.nbytes
if offset < 0:
raise ValueError("offset is negative")
if n < offset: