mirror of
https://github.com/python/cpython.git
synced 2025-09-26 10:19:53 +00:00
gh-94673: Recover Weaklist Lookup Performance (gh-95544)
gh-95302 seems to have introduced a small performance regression. Here we make some minor changes to recover that lost performance.
This commit is contained in:
parent
60f54d9485
commit
bdbadb905a
3 changed files with 47 additions and 7 deletions
|
@ -1505,11 +1505,15 @@ subtype_dealloc(PyObject *self)
|
|||
finalizers since they might rely on part of the object
|
||||
being finalized that has already been destroyed. */
|
||||
if (type->tp_weaklistoffset && !base->tp_weaklistoffset) {
|
||||
/* Modeled after GET_WEAKREFS_LISTPTR() */
|
||||
PyWeakReference **list = (PyWeakReference **) \
|
||||
_PyObject_GET_WEAKREFS_LISTPTR(self);
|
||||
while (*list)
|
||||
/* Modeled after GET_WEAKREFS_LISTPTR().
|
||||
|
||||
This is never triggered for static types so we can avoid the
|
||||
(slightly) more costly _PyObject_GET_WEAKREFS_LISTPTR(). */
|
||||
PyWeakReference **list = \
|
||||
_PyObject_GET_WEAKREFS_LISTPTR_FROM_OFFSET(self);
|
||||
while (*list) {
|
||||
_PyWeakref_ClearRef(*list);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue