@@ -926,8 +926,8 @@ static PyObject *
926
926
_elementtree_Element___getstate___impl (ElementObject * self )
927
927
/*[clinic end generated code: output=37279aeeb6bb5b04 input=f0d16d7ec2f7adc1]*/
928
928
{
929
- Py_ssize_t i , noattrib ;
930
- PyObject * instancedict = NULL , * children ;
929
+ Py_ssize_t i ;
930
+ PyObject * children , * attrib ;
931
931
932
932
/* Build a list of children. */
933
933
children = PyList_New (self -> extra ? self -> extra -> length : 0 );
@@ -939,33 +939,24 @@ _elementtree_Element___getstate___impl(ElementObject *self)
939
939
PyList_SET_ITEM (children , i , child );
940
940
}
941
941
942
- /* Construct the state object. */
943
- noattrib = (self -> extra == NULL || self -> extra -> attrib == Py_None );
944
- if (noattrib )
945
- instancedict = Py_BuildValue ("{sOsOs{}sOsO}" ,
946
- PICKLED_TAG , self -> tag ,
947
- PICKLED_CHILDREN , children ,
948
- PICKLED_ATTRIB ,
949
- PICKLED_TEXT , JOIN_OBJ (self -> text ),
950
- PICKLED_TAIL , JOIN_OBJ (self -> tail ));
951
- else
952
- instancedict = Py_BuildValue ("{sOsOsOsOsO}" ,
953
- PICKLED_TAG , self -> tag ,
954
- PICKLED_CHILDREN , children ,
955
- PICKLED_ATTRIB , self -> extra -> attrib ,
956
- PICKLED_TEXT , JOIN_OBJ (self -> text ),
957
- PICKLED_TAIL , JOIN_OBJ (self -> tail ));
958
- if (instancedict ) {
959
- Py_DECREF (children );
960
- return instancedict ;
942
+ if (self -> extra && self -> extra -> attrib != Py_None ) {
943
+ attrib = self -> extra -> attrib ;
944
+ Py_INCREF (attrib );
961
945
}
962
946
else {
963
- for ( i = 0 ; i < PyList_GET_SIZE ( children ); i ++ )
964
- Py_DECREF ( PyList_GET_ITEM ( children , i ));
965
- Py_DECREF (children );
966
-
967
- return NULL ;
947
+ attrib = PyDict_New ();
948
+ if (! attrib ) {
949
+ Py_DECREF (children );
950
+ return NULL ;
951
+ }
968
952
}
953
+
954
+ return Py_BuildValue ("{sOsNsNsOsO}" ,
955
+ PICKLED_TAG , self -> tag ,
956
+ PICKLED_CHILDREN , children ,
957
+ PICKLED_ATTRIB , attrib ,
958
+ PICKLED_TEXT , JOIN_OBJ (self -> text ),
959
+ PICKLED_TAIL , JOIN_OBJ (self -> tail ));
969
960
}
970
961
971
962
static PyObject *
0 commit comments