[issue9971] Optimize BufferedReader.readinto

Antoine Pitrou report at bugs.python.org
Thu May 5 21:06:15 CEST 2011


Antoine Pitrou <pitrou at free.fr> added the comment:

> As I think about this more... I'm not sure how much performance there
> is to gain here in practice.  It seems like any time I'd want to use
> readinto(), it's because I want to do my own buffering, in which case
> why would I use a BufferedReader?

The difference between buffered I/O and raw I/O isn't only the presence
of a buffer. For example read(N) on a buffered object will loop until N
bytes are satisfied (or EOF is reached), while read(N) on a raw I/O
object will give you whatever the system call returns.

I would add that third-party buffering would be better helped by the
prefetch() method I proposed on python-ideas:
http://mail.python.org/pipermail/python-ideas/2010-September/008179.html

readinto() is really about minimizing copies and allocations when you
already have storage allocated for the result.
(note that TextIOWrapper could have used readinto(), but instead opted
for the slightly useless read1())

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue9971>
_______________________________________


More information about the Python-bugs-list mailing list