Skip to content

Commit 46140c9

Browse files
cmaloneyclaude
andcommitted
gh-87613: Use the AC vectorcall for float
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. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
1 parent a000129 commit 46140c9

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
@@ -5597,7 +5597,8 @@ def through_init(cls):
55975597
return cls, partial(cls.__init__, cls(1))
55985598

55995599
entry_points = [
5600-
through_new(enumerate), # the only non-test @vectorcall function
5600+
through_new(enumerate),
5601+
through_new(float),
56015602
through_new(ac_tester.VcNew),
56025603
through_new(ac_tester.VcNewBase),
56035604
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
@@ -1555,6 +1555,7 @@ static PyObject *
15551555
float_subtype_new(PyTypeObject *type, PyObject *x);
15561556

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

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

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

16301614
/*[clinic input]
16311615
@classmethod

0 commit comments

Comments
 (0)