Skip to content

Commit 50082b8

Browse files
authored
gh-87613: Use AC vectorcall for float (GH-158201)
Move float.__new__ to AC vectorcall dropping the hand-written. Running microbenchmark from the original add (`pyperf timeit "float(0)"` in gh-86039) shows no significant performance change. The generated name matches the hand-written name so the tp_vectorcall slot is unchanged. Update the vectorcall slot-parity test to include float.
1 parent 85bca2d commit 50082b8

3 files changed

Lines changed: 34 additions & 20 deletions

File tree

‎Lib/test/test_clinic.py‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5665,7 +5665,8 @@ def through_init(cls):
56655665
return cls, partial(cls.__init__, cls(1))
56665666

56675667
entry_points = [
5668-
through_new(enumerate), # the only non-test @vectorcall function
5668+
through_new(enumerate),
5669+
through_new(float),
56695670
through_new(ac_tester.VcNew),
56705671
through_new(ac_tester.VcNewBase),
56715672
through_new(ac_tester.VcKwOnly),

‎Objects/clinic/floatobject.c.h‎

Lines changed: 30 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎Objects/floatobject.c‎

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1556,6 +1556,7 @@ static PyObject *
15561556
float_subtype_new(PyTypeObject *type, PyObject *x);
15571557

15581558
/*[clinic input]
1559+
@vectorcall
15591560
@classmethod
15601561
float.__new__ as float_new
15611562
x: object(c_default="NULL") = 0
@@ -1566,7 +1567,7 @@ Convert a string or number to a floating-point number, if possible.
15661567

15671568
static PyObject *
15681569
float_new_impl(PyTypeObject *type, PyObject *x)
1569-
/*[clinic end generated code: output=ccf1e8dc460ba6ba input=55909f888aa0c8a6]*/
1570+
/*[clinic end generated code: output=ccf1e8dc460ba6ba input=39b40d663c372a91]*/
15701571
{
15711572
if (type != &PyFloat_Type) {
15721573
if (x == NULL) {
@@ -1610,23 +1611,6 @@ float_subtype_new(PyTypeObject *type, PyObject *x)
16101611
return newobj;
16111612
}
16121613

1613-
static PyObject *
1614-
float_vectorcall(PyObject *type, PyObject *const *args,
1615-
size_t nargsf, PyObject *kwnames)
1616-
{
1617-
if (!_PyArg_NoKwnames("float", kwnames)) {
1618-
return NULL;
1619-
}
1620-
1621-
Py_ssize_t nargs = PyVectorcall_NARGS(nargsf);
1622-
if (!_PyArg_CheckPositional("float", nargs, 0, 1)) {
1623-
return NULL;
1624-
}
1625-
1626-
PyObject *x = nargs >= 1 ? args[0] : NULL;
1627-
return float_new_impl(_PyType_CAST(type), x);
1628-
}
1629-
16301614

16311615
/*[clinic input]
16321616
@classmethod

0 commit comments

Comments
 (0)