mirror of
https://github.com/python/cpython.git
synced 2025-11-25 04:34:37 +00:00
gh-90667: Add specializations of Py_DECREF when types are known (GH-30872)
This commit is contained in:
parent
ab0d35d70d
commit
da6c78584b
13 changed files with 147 additions and 85 deletions
|
|
@ -238,28 +238,41 @@ PyFloat_FromString(PyObject *v)
|
|||
return result;
|
||||
}
|
||||
|
||||
static void
|
||||
float_dealloc(PyFloatObject *op)
|
||||
void
|
||||
_PyFloat_ExactDealloc(PyObject *obj)
|
||||
{
|
||||
assert(PyFloat_CheckExact(obj));
|
||||
PyFloatObject *op = (PyFloatObject *)obj;
|
||||
#if PyFloat_MAXFREELIST > 0
|
||||
struct _Py_float_state *state = get_float_state();
|
||||
#ifdef Py_DEBUG
|
||||
// float_dealloc() must not be called after _PyFloat_Fini()
|
||||
assert(state->numfree != -1);
|
||||
#endif
|
||||
if (state->numfree >= PyFloat_MAXFREELIST) {
|
||||
PyObject_Free(op);
|
||||
return;
|
||||
}
|
||||
state->numfree++;
|
||||
Py_SET_TYPE(op, (PyTypeObject *)state->free_list);
|
||||
state->free_list = op;
|
||||
#else
|
||||
PyObject_Free(op);
|
||||
#endif
|
||||
}
|
||||
|
||||
static void
|
||||
float_dealloc(PyObject *op)
|
||||
{
|
||||
assert(PyFloat_Check(op));
|
||||
#if PyFloat_MAXFREELIST > 0
|
||||
if (PyFloat_CheckExact(op)) {
|
||||
struct _Py_float_state *state = get_float_state();
|
||||
#ifdef Py_DEBUG
|
||||
// float_dealloc() must not be called after _PyFloat_Fini()
|
||||
assert(state->numfree != -1);
|
||||
#endif
|
||||
if (state->numfree >= PyFloat_MAXFREELIST) {
|
||||
PyObject_Free(op);
|
||||
return;
|
||||
}
|
||||
state->numfree++;
|
||||
Py_SET_TYPE(op, (PyTypeObject *)state->free_list);
|
||||
state->free_list = op;
|
||||
_PyFloat_ExactDealloc(op);
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
Py_TYPE(op)->tp_free((PyObject *)op);
|
||||
Py_TYPE(op)->tp_free(op);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue