]> granicus.if.org Git - python/commitdiff
Be smarter about clearing the weakref lists for instances, instance methods,
authorFred Drake <fdrake@acm.org>
Fri, 26 Oct 2001 17:56:51 +0000 (17:56 +0000)
committerFred Drake <fdrake@acm.org>
Fri, 26 Oct 2001 17:56:51 +0000 (17:56 +0000)
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.

Objects/classobject.c
Objects/funcobject.c

index 622ca5821a546aab95c6ab19a4879a6932e35784..4522097ac84ddeae05a5c019fff3b485cbf03356 100644 (file)
@@ -585,7 +585,8 @@ instance_dealloc(register PyInstanceObject *inst)
        extern long _Py_RefTotal;
 #endif
        _PyObject_GC_UNTRACK(inst);
-       PyObject_ClearWeakRefs((PyObject *) inst);
+       if (inst->in_weakreflist != NULL)
+               PyObject_ClearWeakRefs((PyObject *) inst);
 
        /* Temporarily resurrect the object. */
 #ifdef Py_TRACE_REFS
@@ -2071,7 +2072,8 @@ static void
 instancemethod_dealloc(register PyMethodObject *im)
 {
        _PyObject_GC_UNTRACK(im);
-       PyObject_ClearWeakRefs((PyObject *)im);
+       if (im->im_weakreflist != NULL)
+               PyObject_ClearWeakRefs((PyObject *)im);
        Py_DECREF(im->im_func);
        Py_XDECREF(im->im_self);
        Py_XDECREF(im->im_class);
index 89dd7f9d917c2f02dbfa0a220dcb12d653a80c94..d978c3f07e750f7e44f6e65fa613bc67e0bb703c 100644 (file)
@@ -270,7 +270,8 @@ static void
 func_dealloc(PyFunctionObject *op)
 {
        _PyObject_GC_UNTRACK(op);
-       PyObject_ClearWeakRefs((PyObject *) op);
+       if (op->func_weakreflist != NULL)
+               PyObject_ClearWeakRefs((PyObject *) op);
        Py_DECREF(op->func_code);
        Py_DECREF(op->func_globals);
        Py_DECREF(op->func_name);