Commit c916f5a3 authored by Fred Drake's avatar Fred Drake

Be smarter about clearing the weakref lists for instances, instance methods,

and functions: we only need to call PyObject_ClearWeakRefs() if the weakref
list is non-NULL.  Since these objects are common but weakrefs are still
unusual, saving the call at deallocation time makes a lot of sense.
parent 7408da54
...@@ -585,6 +585,7 @@ instance_dealloc(register PyInstanceObject *inst) ...@@ -585,6 +585,7 @@ instance_dealloc(register PyInstanceObject *inst)
extern long _Py_RefTotal; extern long _Py_RefTotal;
#endif #endif
_PyObject_GC_UNTRACK(inst); _PyObject_GC_UNTRACK(inst);
if (inst->in_weakreflist != NULL)
PyObject_ClearWeakRefs((PyObject *) inst); PyObject_ClearWeakRefs((PyObject *) inst);
/* Temporarily resurrect the object. */ /* Temporarily resurrect the object. */
...@@ -2071,6 +2072,7 @@ static void ...@@ -2071,6 +2072,7 @@ static void
instancemethod_dealloc(register PyMethodObject *im) instancemethod_dealloc(register PyMethodObject *im)
{ {
_PyObject_GC_UNTRACK(im); _PyObject_GC_UNTRACK(im);
if (im->im_weakreflist != NULL)
PyObject_ClearWeakRefs((PyObject *)im); PyObject_ClearWeakRefs((PyObject *)im);
Py_DECREF(im->im_func); Py_DECREF(im->im_func);
Py_XDECREF(im->im_self); Py_XDECREF(im->im_self);
......
...@@ -270,6 +270,7 @@ static void ...@@ -270,6 +270,7 @@ static void
func_dealloc(PyFunctionObject *op) func_dealloc(PyFunctionObject *op)
{ {
_PyObject_GC_UNTRACK(op); _PyObject_GC_UNTRACK(op);
if (op->func_weakreflist != NULL)
PyObject_ClearWeakRefs((PyObject *) op); PyObject_ClearWeakRefs((PyObject *) op);
Py_DECREF(op->func_code); Py_DECREF(op->func_code);
Py_DECREF(op->func_globals); Py_DECREF(op->func_globals);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment