mirror of
https://github.com/python/cpython.git
synced 2025-08-04 08:59:19 +00:00
gh-129005: _pyio.BufferedIO remove copy on readall (#129454)
Slicing buf and appending chunk would always result in a copy. Commonly in a readall() there is no already read data in buf, and the amount of data read may be large, so the copy is expensive.
This commit is contained in:
parent
3bebe46d34
commit
e1c4ba9288
2 changed files with 5 additions and 0 deletions
|
@ -1062,6 +1062,9 @@ class BufferedReader(_BufferedIOMixin):
|
|||
if chunk is None:
|
||||
return buf[pos:] or None
|
||||
else:
|
||||
# Avoid slice + copy if there is no data in buf
|
||||
if not buf:
|
||||
return chunk
|
||||
return buf[pos:] + chunk
|
||||
chunks = [buf[pos:]] # Strip the consumed bytes.
|
||||
current_size = 0
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue