Skip to content

Commit 052ca8f

Browse files
cmaloneyvstinner
andauthored
gh-129005: Update _pyio.BytesIO to use bytearray.resize on write (#129702)
Co-authored-by: Victor Stinner <vstinner@python.org>
1 parent d83a8a2 commit 052ca8f

File tree

1 file changed

+2
-4
lines changed

1 file changed

+2
-4
lines changed

Lib/_pyio.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -937,10 +937,8 @@ def write(self, b):
937937
return 0
938938
pos = self._pos
939939
if pos > len(self._buffer):
940-
# Inserts null bytes between the current end of the file
941-
# and the new write position.
942-
padding = b'\x00' * (pos - len(self._buffer))
943-
self._buffer += padding
940+
# Pad buffer to pos with null bytes.
941+
self._buffer.resize(pos)
944942
self._buffer[pos:pos + n] = b
945943
self._pos += n
946944
return n

0 commit comments

Comments
 (0)