New submission from Nikolaus Rath:

The read1() docstring says: "Reads up to n bytes, with at most one read() 
system call."

However, in the implementation read1() calls peek() to refill the buffer if 
necessary, and then returns whatever is available in the buffer.

This means that read1() will only return up to n bytes if n is smaller than the 
buffer size, otherwise it will return at most <buffer-size> bytes.


With the current implementation, running a loop that calls obj.read1(n) for 
large n is therefore much less performant than a loop that calls 
obj.raw.read(n). 

I think a call to read1(n) with empty buffer should always attempt to read n 
bytes from the raw stream, i.e. the implementation should be changed to match 
the documentation.

----------
components: IO
messages: 193496
nosy: Nikratio
priority: normal
severity: normal
status: open
title: BufferedReader.read1() documentation/implementation difference
versions: Python 3.3

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue18524>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to