8000 gh-129005: Update _pyio.BytesIO to use bytearray.resize on write · cmaloney/cpython@63795c8 · GitHub
[go: up one dir, main page]

Skip to content

Commit 63795c8

Browse files
committed
pythongh-129005: Update _pyio.BytesIO to use bytearray.resize on write
1 parent cdcacec commit 63795c8

File tree

1 file changed

+2
-4
lines changed

1 file changed

+2
-4
lines changed

Lib/_pyio.py

Lines changed: 2 additions & 4 deletions
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+
# Expand the buffer to be able to hold the new bytes.
941+
self._buffer.resize(pos + n)
944942
self._buffer[pos:pos + n] = b
945943
self._pos += n
946944
return n

0 commit comments

Comments
 (0)
0