diff options
author | Fred Drake <fdrake@acm.org> | 2001-10-26 17:56:51 (GMT) |
---|---|---|
committer | Fred Drake <fdrake@acm.org> | 2001-10-26 17:56:51 (GMT) |
commit | c916f5a390b0ca559de54a15d4014e18792674ea (patch) | |
tree | c258ba669054c2b6f28d5294b66681cc81022442 /Objects/classobject.c | |
parent | 7408da54e2b8ca3afef70fef12bf7c9ce804c969 (diff) | |
download | cpython-c916f5a390b0ca559de54a15d4014e18792674ea.zip cpython-c916f5a390b0ca559de54a15d4014e18792674ea.tar.gz cpython-c916f5a390b0ca559de54a15d4014e18792674ea.tar.bz2 |
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.
Diffstat (limited to 'Objects/classobject.c')
-rw-r--r-- | Objects/classobject.c | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/Objects/classobject.c b/Objects/classobject.c index 622ca58..4522097 100644 --- a/Objects/classobject.c +++ b/Objects/classobject.c @@ -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); |