@@ -757,7 +757,7 @@ _PyEval_MatchClass(PyThreadState *tstate, PyObject *subject, PyObject *type,
757757 return NULL ;
758758 }
759759 }
760- PyObject * attrs = PyList_New ( 0 );
760+ PyObject * attrs = PyTuple_New ( nattrs );
761761 if (attrs == NULL ) {
762762 Py_XDECREF (seen );
763763 return NULL ;
@@ -800,9 +800,8 @@ _PyEval_MatchClass(PyThreadState *tstate, PyObject *subject, PyObject *type,
800800 }
801801 if (match_self ) {
802802 // Easy. Copy the subject itself, and move on to kwargs.
803- if (PyList_Append (attrs , subject ) < 0 ) {
804- goto fail ;
805- }
803+ Py_INCREF (subject );
804+ PyTuple_SET_ITEM (attrs , 0 , subject );
806805 }
807806 else {
808807 for (Py_ssize_t i = 0 ; i < nargs ; i ++ ) {
@@ -818,11 +817,7 @@ _PyEval_MatchClass(PyThreadState *tstate, PyObject *subject, PyObject *type,
818817 if (attr == NULL ) {
819818 goto fail ;
820819 }
821- if (PyList_Append (attrs , attr ) < 0 ) {
822- Py_DECREF (attr );
823- goto fail ;
824- }
825- Py_DECREF (attr );
820+ PyTuple_SET_ITEM (attrs , i , attr );
826821 }
827822 }
828823 Py_CLEAR (match_args );
@@ -834,13 +829,8 @@ _PyEval_MatchClass(PyThreadState *tstate, PyObject *subject, PyObject *type,
834829 if (attr == NULL ) {
835830 goto fail ;
836831 }
837- if (PyList_Append (attrs , attr ) < 0 ) {
838- Py_DECREF (attr );
839- goto fail ;
840- }
841- Py_DECREF (attr );
832+ PyTuple_SET_ITEM (attrs , nargs + i , attr );
842833 }
843- Py_SETREF (attrs , PyList_AsTuple (attrs ));
844834 Py_XDECREF (seen );
845835 return attrs ;
846836fail :
0 commit comments