diff options
author | Dennis Sweeney <36520290+sweeneyde@users.noreply.github.com> | 2022-04-19 18:02:19 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-04-19 18:02:19 (GMT) |
commit | da6c78584b1f45ce3766bf7f27fb033169715292 (patch) | |
tree | aadde6ee2f5323357a7e0e8eff7a97f1fd44ec4b /Objects/floatobject.c | |
parent | ab0d35d70dfe0b4c11583f8f735a8cc49b58c58b (diff) | |
download | cpython-da6c78584b1f45ce3766bf7f27fb033169715292.zip cpython-da6c78584b1f45ce3766bf7f27fb033169715292.tar.gz cpython-da6c78584b1f45ce3766bf7f27fb033169715292.tar.bz2 |
gh-90667: Add specializations of Py_DECREF when types are known (GH-30872)
Diffstat (limited to 'Objects/floatobject.c')
-rw-r--r-- | Objects/floatobject.c | 41 |
1 files changed, 27 insertions, 14 deletions
diff --git a/Objects/floatobject.c b/Objects/floatobject.c index 736ddc9..a5774b9 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); } } |