Skip to content

Commit d0d9463

Browse files
committed
pythongh-129005: _pyio.BufferedIO Remove copy on readall
1 parent 871979d commit d0d9463

File tree

2 files changed

+4
-0
lines changed

2 files changed

+4
-0
lines changed

Lib/_pyio.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1062,6 +1062,9 @@ def _read_unlocked(self, n=None):
10621062
if chunk is None:
10631063
return buf[pos:] or None
10641064
else:
1065+
# Avoid slice + copy if there is no data in buf.
1066+
if not buf:
1067+
return chunk
10651068
return buf[pos:] + chunk
10661069
chunks = [buf[pos:]] # Strip the consumed bytes.
10671070
current_size = 0
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Optimize ``_pyio.FileIO.read`` by removing an unnecessary copy

0 commit comments

Comments
 (0)