[issue2523] binary buffered reading is quadratic

Antoine Pitrou report at bugs.python.org
Mon Jul 21 11:30:18 CEST 2008


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

Selon "Martin v. Löwis" <report at bugs.python.org>:
>
> Martin v. Löwis <martin at v.loewis.de> added the comment:
>
> I don't understand the second loop (where n is given). If n is given,
> there should be only a single read operation, using
>
>   max(buffer_size, n-avail)

I mimicked the original logic rather than rethink the algorithm. I'm not totally
sure what motivates the original logic but the purpose seems to be that
non-blocking streams can return at least a few bytes rather than an empty string
when less than N bytes are ready at OS level.

> (i.e. the way it is in patch 2). In particular, if the stream is
> unbuffered, it shouldn't ever end up with buffered data.

Hmm, what do you mean by "if the stream is unbuffered"? Unbuffered streams
should use the raw unbuffered objects (e.g. FileIO) rather than wrap them with
BufferedReader.

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


More information about the Python-bugs-list mailing list