@@ -950,8 +950,8 @@ static PyObject *
950
950
_elementtree_Element___getstate___impl (ElementObject * self )
951
951
/*[clinic end generated code: output=37279aeeb6bb5b04 input=f0d16d7ec2f7adc1]*/
952
952
{
953
- Py_ssize_t i , noattrib ;
954
- PyObject * instancedict = NULL , * children ;
953
+ Py_ssize_t i ;
954
+ PyObject * children , * attrib ;
955
955
956
956
/* Build a list of children. */
957
957
children = PyList_New (self -> extra ? self -> extra -> length : 0 );
@@ -963,33 +963,24 @@ _elementtree_Element___getstate___impl(ElementObject *self)
963
963
PyList_SET_ITEM (children , i , child );
964
964
}
965
965
966
- /* Construct the state object. */
967
- noattrib = (self -> extra == NULL || self -> extra -> attrib == Py_None );
968
- if (noattrib )
969
- instancedict = Py_BuildValue ("{sOsOs{}sOsO}" ,
970
- PICKLED_TAG , self -> tag ,
971
- PICKLED_CHILDREN , children ,
972
- PICKLED_ATTRIB ,
973
- PICKLED_TEXT , JOIN_OBJ (self -> text ),
974
- PICKLED_TAIL , JOIN_OBJ (self -> tail ));
975
- else
976
- instancedict = Py_BuildValue ("{sOsOsOsOsO}" ,
977
- PICKLED_TAG , self -> tag ,
978
- PICKLED_CHILDREN , children ,
979
- PICKLED_ATTRIB , self -> extra -> attrib ,
980
- PICKLED_TEXT , JOIN_OBJ (self -> text ),
981
- PICKLED_TAIL , JOIN_OBJ (self -> tail ));
982
- if (instancedict ) {
983
- Py_DECREF (children );
984
- return instancedict ;
966
+ if (self -> extra && self -> extra -> attrib != Py_None ) {
967
+ attrib = self -> extra -> attrib ;
968
+ Py_INCREF (attrib );
985
969
}
986
970
else {
987
- for ( i = 0 ; i < PyList_GET_SIZE ( children ); i ++ )
988
- Py_DECREF ( PyList_GET_ITEM ( children , i ));
989
- Py_DECREF (children );
990
-
991
- return NULL ;
971
+ attrib = PyDict_New ();
972
+ if (! attrib ) {
973
+ Py_DECREF (children );
974
+ return NULL ;
975
+ }
992
976
}
977
+
978
+ return Py_BuildValue ("{sOsNsNsOsO}" ,
979
+ PICKLED_TAG , self -> tag ,
980
+ PICKLED_CHILDREN , children ,
981
+ PICKLED_ATTRIB , attrib ,
982
+ PICKLED_TEXT , JOIN_OBJ (self -> text ),
983
+ PICKLED_TAIL , JOIN_OBJ (self -> tail ));
993
984
}
994
985
995
986
static PyObject *
0 commit comments