File tree Expand file tree Collapse file tree 2 files changed +7
-59
lines changed Expand file tree Collapse file tree 2 files changed +7
-59
lines changed Original file line number Diff line number Diff line change @@ -3663,44 +3663,14 @@ PyTypeObject PyDictIterItem_Type = {
3663
3663
static PyObject *
3664
3664
dictiter_reduce (dictiterobject * di , PyObject * Py_UNUSED (ignored ))
3665
3665
{
3666
- PyObject * list ;
3667
- dictiterobject tmp ;
3668
-
3669
- list = PyList_New (0 );
3670
- if (!list )
3671
- return NULL ;
3672
-
3673
- /* copy the itertor state */
3674
- tmp = * di ;
3666
+ /* copy the iterator state */
3667
+ dictiterobject tmp = * di ;
3675
3668
Py_XINCREF (tmp .di_dict );
3676
3669
3677
3670
/* iterate the temporary into a list */
3678
- for (;;) {
3679
- PyObject * element = 0 ;
3680
- if (Py_TYPE (di ) == & PyDictIterItem_Type )
3681
- element = dictiter_iternextitem (& tmp );
3682
- else if (Py_TYPE (di ) == & PyDictIterKey_Type )
3683
- element = dictiter_iternextkey (& tmp );
3684
- else if (Py_TYPE (di ) == & PyDictIterValue_Type )
3685
- element = dictiter_iternextvalue (& tmp );
3686
- else
3687
- Py_UNREACHABLE ();
3688
- if (element ) {
3689
- if (PyList_Append (list , element )) {
3690
- Py_DECREF (element );
3691
- Py_DECREF (list );
3692
- Py_XDECREF (tmp .di_dict );
3693
- return NULL ;
3694
- }
3695
- Py_DECREF (element );
3696
- } else
3697
- break ;
3698
- }
3671
+ PyObject * list = PySequence_List ((PyObject * )& tmp );
3699
3672
Py_XDECREF (tmp .di_dict );
3700
- /* check for error */
3701
- if (tmp .di_dict != NULL ) {
3702
- /* we have an error */
3703
- Py_DECREF (list );
3673
+ if (list == NULL ) {
3704
3674
return NULL ;
3705
3675
}
3706
3676
return Py_BuildValue ("N(N)" , _PyObject_GetBuiltin ("iter" ), list );
Original file line number Diff line number Diff line change @@ -843,36 +843,14 @@ static PyObject *setiter_iternext(setiterobject *si);
843
843
static PyObject *
844
844
setiter_reduce (setiterobject * si , PyObject * Py_UNUSED (ignored ))
845
845
{
846
- PyObject * list ;
847
- setiterobject tmp ;
848
-
849
- list = PyList_New (0 );
850
- if (!list )
851
- return NULL ;
852
-
853
846
/* copy the iterator state */
854
- tmp = * si ;
847
+ setiterobject tmp = * si ;
855
848
Py_XINCREF (tmp .si_set );
856
849
857
850
/* iterate the temporary into a list */
858
- for (;;) {
859
- PyObject * element = setiter_iternext (& tmp );
860
- if (element ) {
861
- if (PyList_Append (list , element )) {
862
- Py_DECREF (element );
863
- Py_DECREF (list );
864
- Py_XDECREF (tmp .si_set );
865
- return NULL ;
866
- }
867
- Py_DECREF (element );
868
- } else
869
- break ;
870
- }
851
+ PyObject * list = PySequence_List ((PyObject * )& tmp );
871
852
Py_XDECREF (tmp .si_set );
872
- /* check for error */
873
- if (tmp .si_set != NULL ) {
874
- /* we have an error */
875
- Py_DECREF (list );
853
+ if (list == NULL ) {
876
854
return NULL ;
877
855
}
878
856
return Py_BuildValue ("N(N)" , _PyObject_GetBuiltin ("iter" ), list );
You can’t perform that action at this time.
0 commit comments