From da6c78584b1f45ce3766bf7f27fb033169715292 Mon Sep 17 00:00:00 2001 From: Dennis Sweeney <36520290+sweeneyde@users.noreply.github.com> Date: Tue, 19 Apr 2022 14:02:19 -0400 Subject: gh-90667: Add specializations of Py_DECREF when types are known (GH-30872) --- Objects/floatobject.c | 41 +++++++++++++++++++++++++++-------------- 1 file changed, 27 insertions(+), 14 deletions(-) (limited to 'Objects/floatobject.c') diff --git a/Objects/floatobject.c b/Objects/floatobject.c index 736ddc95d6..a5774b9e30 100644 --- a/Objects/floatobject.c +++ b/Objects/floatobject.c @@ -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 - if (PyFloat_CheckExact(op)) { - struct _Py_float_state *state = get_float_state(); + struct _Py_float_state *state = get_float_state(); #ifdef Py_DEBUG - // float_dealloc() must not be called after _PyFloat_Fini() - assert(state->numfree != -1); + // 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; + 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)) { + _PyFloat_ExactDealloc(op); } else #endif { - Py_TYPE(op)->tp_free((PyObject *)op); + Py_TYPE(op)->tp_free(op); } } -- cgit v1.2.1