]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
GH-91355: micro-optimize Connection.send_bytes() method (gh-32247)
authorMa Lin <animalize@users.noreply.github.com>
Tue, 3 May 2022 14:41:45 +0000 (22:41 +0800)
committerGitHub <noreply@github.com>
Tue, 3 May 2022 14:41:45 +0000 (23:41 +0900)
Lib/multiprocessing/connection.py

index 1cca66d5661e34ce77e0db6ac31bf568eb16bd0e..65303d29f51f8f39ccf5a1742c80b2bb527c28c6 100644 (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: