Message 97251 - Python tracker (original) (raw)

Thank you. Are you sure the "Shortcut common case" in readline() is useful? BufferedIOBase.readline() in itself should be rather fast.

On my dataset the shortcut speeds up readline() 400% on top of the default C implementation.

I can take a look to why the C implementation is slow (although it is documented as "slowish").

Also, I'm not sure what happens in readline() in universal mode when the chunk ends with a '\r' and there's a '\n' in the following chunk (see the "ugly check" that your patch removes). Is there a test for that?

The regular pattern returns either a line chunk or a newline (sequence) but not both. To read a line there is therefore a minimum of two peek() calls. One for the line content and the last for the newline. Since the peek is called with a value of 2, the newline sequence \r\n should be retrieved as is. There is no test for that.