@@ -935,9 +935,8 @@ element_setstate_from_attributes(ElementObject *self,
935935 return NULL ;
936936 }
937937
938- Py_CLEAR (self -> tag );
939- self -> tag = tag ;
940- Py_INCREF (self -> tag );
938+ Py_INCREF (tag );
939+ Py_SETREF (self -> tag , tag );
941940
942941 _clear_joined_ptr (& self -> text );
943942 self -> text = text ? JOIN_SET (text , PyList_CheckExact (text )) : Py_None ;
@@ -980,9 +979,8 @@ element_setstate_from_attributes(ElementObject *self,
980979
981980 /* Stash attrib. */
982981 if (attrib ) {
983- Py_CLEAR (self -> extra -> attrib );
984- self -> extra -> attrib = attrib ;
985982 Py_INCREF (attrib );
983+ Py_SETREF (self -> extra -> attrib , attrib );
986984 }
987985
988986 Py_RETURN_NONE ;
@@ -1944,9 +1942,8 @@ element_setattro(ElementObject* self, PyObject* nameobj, PyObject* value)
19441942 return -1 ;
19451943
19461944 if (strcmp (name , "tag" ) == 0 ) {
1947- Py_DECREF (self -> tag );
1948- self -> tag = value ;
1949- Py_INCREF (self -> tag );
1945+ Py_INCREF (value );
1946+ Py_SETREF (self -> tag , value );
19501947 } else if (strcmp (name , "text" ) == 0 ) {
19511948 Py_DECREF (JOIN_OBJ (self -> text ));
19521949 self -> text = value ;
@@ -1960,9 +1957,8 @@ element_setattro(ElementObject* self, PyObject* nameobj, PyObject* value)
19601957 if (create_extra (self , NULL ) < 0 )
19611958 return -1 ;
19621959 }
1963- Py_DECREF (self -> extra -> attrib );
1964- self -> extra -> attrib = value ;
1965- Py_INCREF (self -> extra -> attrib );
1960+ Py_INCREF (value );
1961+ Py_SETREF (self -> extra -> attrib , value );
19661962 } else {
19671963 PyErr_SetString (PyExc_AttributeError ,
19681964 "Can't set arbitrary attributes on Element" );
@@ -2554,13 +2550,10 @@ treebuilder_handle_start(TreeBuilderObject* self, PyObject* tag,
25542550 }
25552551 self -> index ++ ;
25562552
2557- Py_DECREF (this );
25582553 Py_INCREF (node );
2559- self -> this = node ;
2560-
2561- Py_DECREF (self -> last );
2554+ Py_SETREF (self -> this , node );
25622555 Py_INCREF (node );
2563- self -> last = node ;
2556+ Py_SETREF ( self -> last , node ) ;
25642557
25652558 if (treebuilder_append_event (self , self -> start_event_obj , node ) < 0 )
25662559 goto error ;
@@ -2633,15 +2626,12 @@ treebuilder_handle_end(TreeBuilderObject* self, PyObject* tag)
26332626 return NULL ;
26342627 }
26352628
2636- self -> index -- ;
2637-
2638- item = PyList_GET_ITEM (self -> stack , self -> index );
2639- Py_INCREF (item );
2640-
2641- Py_DECREF (self -> last );
2642-
2629+ item = self -> last ;
26432630 self -> last = self -> this ;
2644- self -> this = item ;
2631+ self -> index -- ;
2632+ self -> this = PyList_GET_ITEM (self -> stack , self -> index );
2633+ Py_INCREF (self -> this );
2634+ Py_DECREF (item );
26452635
26462636 if (treebuilder_append_event (self , self -> end_event_obj , self -> last ) < 0 )
26472637 return NULL ;
0 commit comments