Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit fd82113

Browse files
author
Victor Stinner
committed
Fast path for IncrementalNewlineDecoder.decode() in io.TextIOWrapper.read(-1)
Copy/paste code from textiowrapper_read_chunk().
1 parent 242926d commit fd82113

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

Modules/_io/textio.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1513,8 +1513,13 @@ textiowrapper_read(textio *self, PyObject *args)
15131513
PyObject *decoded;
15141514
if (bytes == NULL)
15151515
goto fail;
1516-
decoded = PyObject_CallMethodObjArgs(self->decoder, _PyIO_str_decode,
1517-
bytes, Py_True, NULL);
1516+
1517+
if (Py_TYPE(self->decoder) == &PyIncrementalNewlineDecoder_Type)
1518+
decoded = _PyIncrementalNewlineDecoder_decode(self->decoder,
1519+
bytes, 1);
1520+
else
1521+
decoded = PyObject_CallMethodObjArgs(
1522+
self->decoder, _PyIO_str_decode, bytes, Py_True, NULL);
15181523
Py_DECREF(bytes);
15191524
if (decoded == NULL)
15201525
goto fail;

0 commit comments

Comments
 (0)