summaryrefslogtreecommitdiffstats
path: root/Modules/gcmodule.c
diff options
context:
space:
mode:
authorEric Snow <ericsnowcurrently@gmail.com>2022-08-04 17:28:15 (GMT)
committerGitHub <noreply@github.com>2022-08-04 17:28:15 (GMT)
commitbdbadb905ae638b67a6c9a6767be396e18839dd6 (patch)
treeb43f9af37788bcef962f8d87fbacaca57289b0dd /Modules/gcmodule.c
parent60f54d94852771854cf1cb647df7cef7c1617d9e (diff)
downloadcpython-bdbadb905ae638b67a6c9a6767be396e18839dd6.zip
cpython-bdbadb905ae638b67a6c9a6767be396e18839dd6.tar.gz
cpython-bdbadb905ae638b67a6c9a6767be396e18839dd6.tar.bz2
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.
Diffstat (limited to 'Modules/gcmodule.c')
-rw-r--r--Modules/gcmodule.c9
1 files changed, 6 insertions, 3 deletions
diff --git a/Modules/gcmodule.c b/Modules/gcmodule.c
index dcd46fe..97cb6e6 100644
--- a/Modules/gcmodule.c
+++ b/Modules/gcmodule.c
@@ -794,9 +794,12 @@ handle_weakrefs(PyGC_Head *unreachable, PyGC_Head *old)
if (! _PyType_SUPPORTS_WEAKREFS(Py_TYPE(op)))
continue;
- /* It supports weakrefs. Does it have any? */
- wrlist = (PyWeakReference **)
- _PyObject_GET_WEAKREFS_LISTPTR(op);
+ /* It supports weakrefs. Does it have any?
+ *
+ * This is never triggered for static types so we can avoid the
+ * (slightly) more costly _PyObject_GET_WEAKREFS_LISTPTR().
+ */
+ wrlist = _PyObject_GET_WEAKREFS_LISTPTR_FROM_OFFSET(op);
/* `op` may have some weakrefs. March over the list, clear
* all the weakrefs, and move the weakrefs with callbacks