Skip to content

Commit 2b9134b

Browse files
fix performance regression in PyType_GetModuleByDef on free-threading
1 parent 3b93979 commit 2b9134b

1 file changed

Lines changed: 7 additions & 9 deletions

File tree

Objects/typeobject.c

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5878,22 +5878,20 @@ PyType_GetModuleByToken_DuringGC(PyTypeObject *type, const void *token)
58785878
PyObject *
58795879
PyType_GetModuleByToken(PyTypeObject *type, const void *token)
58805880
{
5881-
PyObject *mod = PyType_GetModuleByToken_DuringGC(type, token);
5881+
return Py_XNewRef(PyType_GetModuleByDef(type, (PyModuleDef *)token));
5882+
}
5883+
5884+
PyObject *
5885+
PyType_GetModuleByDef(PyTypeObject *type, PyModuleDef *def)
5886+
{
5887+
PyObject *mod = PyType_GetModuleByToken_DuringGC(type, def);
58825888
if (!mod) {
58835889
PyErr_Format(
58845890
PyExc_TypeError,
58855891
"PyType_GetModuleByDef: No superclass of '%s' has the given module",
58865892
type->tp_name);
58875893
return NULL;
58885894
}
5889-
return Py_NewRef(mod);
5890-
}
5891-
5892-
PyObject *
5893-
PyType_GetModuleByDef(PyTypeObject *type, PyModuleDef *def)
5894-
{
5895-
PyObject *mod = PyType_GetModuleByToken(type, def);
5896-
Py_XDECREF(mod); // return borrowed ref
58975895
return mod;
58985896
}
58995897

0 commit comments

Comments
 (0)