File tree Expand file tree Collapse file tree 1 file changed +13
-14
lines changed Expand file tree Collapse file tree 1 file changed +13
-14
lines changed Original file line number Diff line number Diff line change @@ -962,11 +962,10 @@ static PyObject *
962962_io__RawIOBase_readall_impl (PyObject * self )
963963/*[clinic end generated code: output=1987b9ce929425a0 input=688874141213622a]*/
964964{
965- int r ;
966- PyObject * chunks = PyList_New (0 );
965+ PyBytesWriter * writer = PyBytesWriter_Create (0 );
967966 PyObject * result ;
968967
969- if (chunks == NULL )
968+ if (writer == NULL )
970969 return NULL ;
971970
972971 while (1 ) {
@@ -978,38 +977,38 @@ _io__RawIOBase_readall_impl(PyObject *self)
978977 if (_PyIO_trap_eintr ()) {
979978 continue ;
980979 }
981- Py_DECREF ( chunks );
980+ PyBytesWriter_Discard ( writer );
982981 return NULL ;
983982 }
984983 if (data == Py_None ) {
985- if (PyList_GET_SIZE ( chunks ) == 0 ) {
986- Py_DECREF ( chunks );
984+ if (PyBytesWriter_GetSize ( writer ) == 0 ) {
985+ PyBytesWriter_Discard ( writer );
987986 return data ;
988987 }
989988 Py_DECREF (data );
990989 break ;
991990 }
992991 if (!PyBytes_Check (data )) {
993- Py_DECREF (chunks );
994992 Py_DECREF (data );
995993 PyErr_SetString (PyExc_TypeError , "read() should return bytes" );
994+ PyBytesWriter_Discard (writer );
996995 return NULL ;
997996 }
998997 if (PyBytes_GET_SIZE (data ) == 0 ) {
999998 /* EOF */
1000999 Py_DECREF (data );
10011000 break ;
10021001 }
1003- r = PyList_Append (chunks , data );
1004- Py_DECREF (data );
1005- if (r < 0 ) {
1006- Py_DECREF (chunks );
1002+ if (PyBytesWriter_WriteBytes (writer ,
1003+ PyBytes_AS_STRING (data ),
1004+ PyBytes_GET_SIZE (data )) < 0 ) {
1005+ Py_DECREF (data );
1006+ PyBytesWriter_Discard (writer );
10071007 return NULL ;
10081008 }
1009+ Py_DECREF (data );
10091010 }
1010- result = PyBytes_Join ((PyObject * )& _Py_SINGLETON (bytes_empty ), chunks );
1011- Py_DECREF (chunks );
1012- return result ;
1011+ return PyBytesWriter_Finish (writer );
10131012}
10141013
10151014static PyObject *
You can’t perform that action at this time.
0 commit comments