mirror of
https://github.com/python/cpython.git
synced 2025-08-31 14:07:50 +00:00
gh-129005: Update _pyio.BytesIO to use bytearray.resize on write (#129702)
Co-authored-by: Victor Stinner <vstinner@python.org>
This commit is contained in:
parent
d83a8a26f5
commit
052ca8ffe8
1 changed files with 2 additions and 4 deletions
|
@ -937,10 +937,8 @@ class BytesIO(BufferedIOBase):
|
|||
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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue