summaryrefslogtreecommitdiffstats
path: root/Objects/floatobject.c
diff options
context:
space:
mode:
Diffstat (limited to 'Objects/floatobject.c')
-rw-r--r--Objects/floatobject.c68
1 files changed, 7 insertions, 61 deletions
diff --git a/Objects/floatobject.c b/Objects/floatobject.c
index 08d8d85..82f39de 100644
--- a/Objects/floatobject.c
+++ b/Objects/floatobject.c
@@ -7,8 +7,8 @@
#include "pycore_abstract.h" // _PyNumber_Index()
#include "pycore_dtoa.h" // _Py_dg_dtoa()
#include "pycore_floatobject.h" // _PyFloat_FormatAdvancedWriter()
+#include "pycore_freelist.h" // _Py_FREELIST_FREE(), _Py_FREELIST_POP()
#include "pycore_initconfig.h" // _PyStatus_OK()
-#include "pycore_interp.h" // _Py_float_freelist
#include "pycore_long.h" // _PyLong_GetOne()
#include "pycore_modsupport.h" // _PyArg_NoKwnames()
#include "pycore_object.h" // _PyObject_Init(), _PyDebugAllocatorStats()
@@ -26,16 +26,6 @@ class float "PyObject *" "&PyFloat_Type"
#include "clinic/floatobject.c.h"
-#ifdef WITH_FREELISTS
-static struct _Py_float_freelist *
-get_float_freelist(void)
-{
- struct _Py_object_freelists *freelists = _Py_object_freelists_GET();
- assert(freelists != NULL);
- return &freelists->floats;
-}
-#endif
-
double
PyFloat_GetMax(void)
@@ -132,24 +122,14 @@ PyFloat_GetInfo(void)
PyObject *
PyFloat_FromDouble(double fval)
{
- PyFloatObject *op;
-#ifdef WITH_FREELISTS
- struct _Py_float_freelist *float_freelist = get_float_freelist();
- op = float_freelist->items;
- if (op != NULL) {
- float_freelist->items = (PyFloatObject *) Py_TYPE(op);
- float_freelist->numfree--;
- OBJECT_STAT_INC(from_freelist);
- }
- else
-#endif
- {
+ PyFloatObject *op = _Py_FREELIST_POP(PyFloatObject, floats);
+ if (op == NULL) {
op = PyObject_Malloc(sizeof(PyFloatObject));
if (!op) {
return PyErr_NoMemory();
}
+ _PyObject_Init((PyObject*)op, &PyFloat_Type);
}
- _PyObject_Init((PyObject*)op, &PyFloat_Type);
op->ob_fval = fval;
return (PyObject *) op;
}
@@ -248,20 +228,7 @@ void
_PyFloat_ExactDealloc(PyObject *obj)
{
assert(PyFloat_CheckExact(obj));
- PyFloatObject *op = (PyFloatObject *)obj;
-#ifdef WITH_FREELISTS
- struct _Py_float_freelist *float_freelist = get_float_freelist();
- if (float_freelist->numfree >= PyFloat_MAXFREELIST || float_freelist->numfree < 0) {
- PyObject_Free(op);
- return;
- }
- float_freelist->numfree++;
- Py_SET_TYPE(op, (PyTypeObject *)float_freelist->items);
- float_freelist->items = op;
- OBJECT_STAT_INC(to_freelist);
-#else
- PyObject_Free(op);
-#endif
+ _Py_FREELIST_FREE(floats, obj, PyObject_Free);
}
static void
@@ -1995,27 +1962,6 @@ _PyFloat_InitTypes(PyInterpreterState *interp)
}
void
-_PyFloat_ClearFreeList(struct _Py_object_freelists *freelists, int is_finalization)
-{
-#ifdef WITH_FREELISTS
- struct _Py_float_freelist *state = &freelists->floats;
- PyFloatObject *f = state->items;
- while (f != NULL) {
- PyFloatObject *next = (PyFloatObject*) Py_TYPE(f);
- PyObject_Free(f);
- f = next;
- }
- state->items = NULL;
- if (is_finalization) {
- state->numfree = -1;
- }
- else {
- state->numfree = 0;
- }
-#endif
-}
-
-void
_PyFloat_FiniType(PyInterpreterState *interp)
{
_PyStructSequence_FiniBuiltin(interp, &FloatInfoType);
@@ -2026,10 +1972,10 @@ void
_PyFloat_DebugMallocStats(FILE *out)
{
#ifdef WITH_FREELISTS
- struct _Py_float_freelist *float_freelist = get_float_freelist();
_PyDebugAllocatorStats(out,
"free PyFloatObject",
- float_freelist->numfree, sizeof(PyFloatObject));
+ _Py_FREELIST_SIZE(floats),
+ sizeof(PyFloatObject));
#endif
}