bpo-41873: Add vectorcall for float() (GH-22432)
This commit is contained in:
parent
cb6db8b6ae
commit
e8acc355d4
|
@ -64,6 +64,9 @@ class GeneralFloatCases(unittest.TestCase):
|
||||||
# See bpo-34087
|
# See bpo-34087
|
||||||
self.assertRaises(ValueError, float, '\u3053\u3093\u306b\u3061\u306f')
|
self.assertRaises(ValueError, float, '\u3053\u3093\u306b\u3061\u306f')
|
||||||
|
|
||||||
|
def test_noargs(self):
|
||||||
|
self.assertEqual(float(), 0.0)
|
||||||
|
|
||||||
def test_underscores(self):
|
def test_underscores(self):
|
||||||
for lit in VALID_UNDERSCORE_LITERALS:
|
for lit in VALID_UNDERSCORE_LITERALS:
|
||||||
if not any(ch in lit for ch in 'jJxXoObB'):
|
if not any(ch in lit for ch in 'jJxXoObB'):
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
Calls to ``float()`` are now faster due to the ``vectorcall`` calling convention. Patch by Dennis Sweeney.
|
|
@ -1649,6 +1649,24 @@ float_subtype_new(PyTypeObject *type, PyObject *x)
|
||||||
return newobj;
|
return newobj;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static PyObject *
|
||||||
|
float_vectorcall(PyObject *type, PyObject * const*args,
|
||||||
|
size_t nargsf, PyObject *kwnames)
|
||||||
|
{
|
||||||
|
if (!_PyArg_NoKwnames("float", kwnames)) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
Py_ssize_t nargs = PyVectorcall_NARGS(nargsf);
|
||||||
|
if (!_PyArg_CheckPositional("float", nargs, 0, 1)) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
PyObject *x = nargs >= 1 ? args[0] : _PyLong_Zero;
|
||||||
|
return float_new_impl((PyTypeObject *)type, x);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/*[clinic input]
|
/*[clinic input]
|
||||||
float.__getnewargs__
|
float.__getnewargs__
|
||||||
[clinic start generated code]*/
|
[clinic start generated code]*/
|
||||||
|
@ -1937,6 +1955,7 @@ PyTypeObject PyFloat_Type = {
|
||||||
0, /* tp_init */
|
0, /* tp_init */
|
||||||
0, /* tp_alloc */
|
0, /* tp_alloc */
|
||||||
float_new, /* tp_new */
|
float_new, /* tp_new */
|
||||||
|
.tp_vectorcall = (vectorcallfunc)float_vectorcall,
|
||||||
};
|
};
|
||||||
|
|
||||||
int
|
int
|
||||||
|
|
Loading…
Reference in New Issue