Skip to content

Commit 9487962

Browse files
committed
Inline PyFloat_FromDouble
1 parent 1a89991 commit 9487962

2 files changed

Lines changed: 14 additions & 2 deletions

File tree

Include/internal/pycore_freelist_state.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ extern "C" {
1515
# define Py_tuple_iters_MAXFREELIST 10
1616
# define Py_dicts_MAXFREELIST 80
1717
# define Py_dictkeys_MAXFREELIST 80
18-
# define Py_floats_MAXFREELIST 100
18+
# define Py_floats_MAXFREELIST 500
1919
# define Py_ints_MAXFREELIST 100
2020
# define Py_slices_MAXFREELIST 1
2121
# define Py_ranges_MAXFREELIST 6

Objects/floatobject.c

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,19 @@ _PyStackRef _PyFloat_FromDouble_ConsumeInputs(_PyStackRef left, _PyStackRef righ
139139
{
140140
PyStackRef_CLOSE_SPECIALIZED(left, _PyFloat_ExactDealloc);
141141
PyStackRef_CLOSE_SPECIALIZED(right, _PyFloat_ExactDealloc);
142-
return PyStackRef_FromPyObjectSteal(PyFloat_FromDouble(value));
142+
143+
PyFloatObject *op = _Py_FREELIST_POP(PyFloatObject, floats);
144+
if (op == NULL) {
145+
op = PyObject_Malloc(sizeof(PyFloatObject));
146+
if (!op) {
147+
PyErr_NoMemory(); // Ensure error is set
148+
return PyStackRef_FromPyObjectSteal(NULL);
149+
}
150+
_PyObject_Init((PyObject*)op, &PyFloat_Type);
151+
}
152+
op->ob_fval = value;
153+
154+
return PyStackRef_FromPyObjectSteal((PyObject *)op);
143155
}
144156

145157
static PyObject *

0 commit comments

Comments
 (0)