https://github.com/python/cpython/commit/052ca8ffe8c57afb9c270fcc4eb5f390cbcfb8ce
commit: 052ca8ffe8c57afb9c270fcc4eb5f390cbcfb8ce
branch: main
author: Cody Maloney <[email protected]>
committer: vstinner <[email protected]>
date: 2025-02-06T10:18:08Z
summary:

gh-129005: Update _pyio.BytesIO to use bytearray.resize on write (#129702)

Co-authored-by: Victor Stinner <[email protected]>

files:
M Lib/_pyio.py

diff --git a/Lib/_pyio.py b/Lib/_pyio.py
index 023478aa78c6a0..b3a8f37d68acdb 100644
--- a/Lib/_pyio.py
+++ b/Lib/_pyio.py
@@ -937,10 +937,8 @@ def write(self, b):
             return 0
         pos = self._pos
         if pos > len(self._buffer):
-            # Inserts null bytes between the current end of the file
-            # and the new write position.
-            padding = b'\x00' * (pos - len(self._buffer))
-            self._buffer += padding
+            # Pad buffer to pos with null bytes.
+            self._buffer.resize(pos)
         self._buffer[pos:pos + n] = b
         self._pos += n
         return n

_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-checkins.python.org/
Member address: [email protected]

Reply via email to