mirror of
https://github.com/python/cpython.git
synced 2025-07-24 11:44:31 +00:00
bpo-35582: Argument Clinic: Optimize the "all boring objects" case. (GH-11520)
Use _PyArg_CheckPositional() and inlined code instead of PyArg_UnpackTuple() and _PyArg_UnpackStack() if all parameters are positional and use the "object" converter.
This commit is contained in:
parent
4fa9591025
commit
2a39d251f0
30 changed files with 561 additions and 408 deletions
29
Objects/clinic/bytearrayobject.c.h
generated
29
Objects/clinic/bytearrayobject.c.h
generated
|
@ -545,11 +545,14 @@ bytearray_strip(PyByteArrayObject *self, PyObject *const *args, Py_ssize_t nargs
|
|||
PyObject *return_value = NULL;
|
||||
PyObject *bytes = Py_None;
|
||||
|
||||
if (!_PyArg_UnpackStack(args, nargs, "strip",
|
||||
0, 1,
|
||||
&bytes)) {
|
||||
if (!_PyArg_CheckPositional("strip", nargs, 0, 1)) {
|
||||
goto exit;
|
||||
}
|
||||
if (nargs < 1) {
|
||||
goto skip_optional;
|
||||
}
|
||||
bytes = args[0];
|
||||
skip_optional:
|
||||
return_value = bytearray_strip_impl(self, bytes);
|
||||
|
||||
exit:
|
||||
|
@ -576,11 +579,14 @@ bytearray_lstrip(PyByteArrayObject *self, PyObject *const *args, Py_ssize_t narg
|
|||
PyObject *return_value = NULL;
|
||||
PyObject *bytes = Py_None;
|
||||
|
||||
if (!_PyArg_UnpackStack(args, nargs, "lstrip",
|
||||
0, 1,
|
||||
&bytes)) {
|
||||
if (!_PyArg_CheckPositional("lstrip", nargs, 0, 1)) {
|
||||
goto exit;
|
||||
}
|
||||
if (nargs < 1) {
|
||||
goto skip_optional;
|
||||
}
|
||||
bytes = args[0];
|
||||
skip_optional:
|
||||
return_value = bytearray_lstrip_impl(self, bytes);
|
||||
|
||||
exit:
|
||||
|
@ -607,11 +613,14 @@ bytearray_rstrip(PyByteArrayObject *self, PyObject *const *args, Py_ssize_t narg
|
|||
PyObject *return_value = NULL;
|
||||
PyObject *bytes = Py_None;
|
||||
|
||||
if (!_PyArg_UnpackStack(args, nargs, "rstrip",
|
||||
0, 1,
|
||||
&bytes)) {
|
||||
if (!_PyArg_CheckPositional("rstrip", nargs, 0, 1)) {
|
||||
goto exit;
|
||||
}
|
||||
if (nargs < 1) {
|
||||
goto skip_optional;
|
||||
}
|
||||
bytes = args[0];
|
||||
skip_optional:
|
||||
return_value = bytearray_rstrip_impl(self, bytes);
|
||||
|
||||
exit:
|
||||
|
@ -815,4 +824,4 @@ bytearray_sizeof(PyByteArrayObject *self, PyObject *Py_UNUSED(ignored))
|
|||
{
|
||||
return bytearray_sizeof_impl(self);
|
||||
}
|
||||
/*[clinic end generated code: output=010e281b823d7df1 input=a9049054013a1b77]*/
|
||||
/*[clinic end generated code: output=f4353c27dcb4a13d input=a9049054013a1b77]*/
|
||||
|
|
29
Objects/clinic/bytesobject.c.h
generated
29
Objects/clinic/bytesobject.c.h
generated
|
@ -203,11 +203,14 @@ bytes_strip(PyBytesObject *self, PyObject *const *args, Py_ssize_t nargs)
|
|||
PyObject *return_value = NULL;
|
||||
PyObject *bytes = Py_None;
|
||||
|
||||
if (!_PyArg_UnpackStack(args, nargs, "strip",
|
||||
0, 1,
|
||||
&bytes)) {
|
||||
if (!_PyArg_CheckPositional("strip", nargs, 0, 1)) {
|
||||
goto exit;
|
||||
}
|
||||
if (nargs < 1) {
|
||||
goto skip_optional;
|
||||
}
|
||||
bytes = args[0];
|
||||
skip_optional:
|
||||
return_value = bytes_strip_impl(self, bytes);
|
||||
|
||||
exit:
|
||||
|
@ -234,11 +237,14 @@ bytes_lstrip(PyBytesObject *self, PyObject *const *args, Py_ssize_t nargs)
|
|||
PyObject *return_value = NULL;
|
||||
PyObject *bytes = Py_None;
|
||||
|
||||
if (!_PyArg_UnpackStack(args, nargs, "lstrip",
|
||||
0, 1,
|
||||
&bytes)) {
|
||||
if (!_PyArg_CheckPositional("lstrip", nargs, 0, 1)) {
|
||||
goto exit;
|
||||
}
|
||||
if (nargs < 1) {
|
||||
goto skip_optional;
|
||||
}
|
||||
bytes = args[0];
|
||||
skip_optional:
|
||||
return_value = bytes_lstrip_impl(self, bytes);
|
||||
|
||||
exit:
|
||||
|
@ -265,11 +271,14 @@ bytes_rstrip(PyBytesObject *self, PyObject *const *args, Py_ssize_t nargs)
|
|||
PyObject *return_value = NULL;
|
||||
PyObject *bytes = Py_None;
|
||||
|
||||
if (!_PyArg_UnpackStack(args, nargs, "rstrip",
|
||||
0, 1,
|
||||
&bytes)) {
|
||||
if (!_PyArg_CheckPositional("rstrip", nargs, 0, 1)) {
|
||||
goto exit;
|
||||
}
|
||||
if (nargs < 1) {
|
||||
goto skip_optional;
|
||||
}
|
||||
bytes = args[0];
|
||||
skip_optional:
|
||||
return_value = bytes_rstrip_impl(self, bytes);
|
||||
|
||||
exit:
|
||||
|
@ -559,4 +568,4 @@ bytes_fromhex(PyTypeObject *type, PyObject *arg)
|
|||
exit:
|
||||
return return_value;
|
||||
}
|
||||
/*[clinic end generated code: output=810c8dfc72520ca4 input=a9049054013a1b77]*/
|
||||
/*[clinic end generated code: output=c6621bda84e63e51 input=a9049054013a1b77]*/
|
||||
|
|
32
Objects/clinic/dictobject.c.h
generated
32
Objects/clinic/dictobject.c.h
generated
|
@ -21,11 +21,15 @@ dict_fromkeys(PyTypeObject *type, PyObject *const *args, Py_ssize_t nargs)
|
|||
PyObject *iterable;
|
||||
PyObject *value = Py_None;
|
||||
|
||||
if (!_PyArg_UnpackStack(args, nargs, "fromkeys",
|
||||
1, 2,
|
||||
&iterable, &value)) {
|
||||
if (!_PyArg_CheckPositional("fromkeys", nargs, 1, 2)) {
|
||||
goto exit;
|
||||
}
|
||||
iterable = args[0];
|
||||
if (nargs < 2) {
|
||||
goto skip_optional;
|
||||
}
|
||||
value = args[1];
|
||||
skip_optional:
|
||||
return_value = dict_fromkeys_impl(type, iterable, value);
|
||||
|
||||
exit:
|
||||
|
@ -60,11 +64,15 @@ dict_get(PyDictObject *self, PyObject *const *args, Py_ssize_t nargs)
|
|||
PyObject *key;
|
||||
PyObject *default_value = Py_None;
|
||||
|
||||
if (!_PyArg_UnpackStack(args, nargs, "get",
|
||||
1, 2,
|
||||
&key, &default_value)) {
|
||||
if (!_PyArg_CheckPositional("get", nargs, 1, 2)) {
|
||||
goto exit;
|
||||
}
|
||||
key = args[0];
|
||||
if (nargs < 2) {
|
||||
goto skip_optional;
|
||||
}
|
||||
default_value = args[1];
|
||||
skip_optional:
|
||||
return_value = dict_get_impl(self, key, default_value);
|
||||
|
||||
exit:
|
||||
|
@ -93,11 +101,15 @@ dict_setdefault(PyDictObject *self, PyObject *const *args, Py_ssize_t nargs)
|
|||
PyObject *key;
|
||||
PyObject *default_value = Py_None;
|
||||
|
||||
if (!_PyArg_UnpackStack(args, nargs, "setdefault",
|
||||
1, 2,
|
||||
&key, &default_value)) {
|
||||
if (!_PyArg_CheckPositional("setdefault", nargs, 1, 2)) {
|
||||
goto exit;
|
||||
}
|
||||
key = args[0];
|
||||
if (nargs < 2) {
|
||||
goto skip_optional;
|
||||
}
|
||||
default_value = args[1];
|
||||
skip_optional:
|
||||
return_value = dict_setdefault_impl(self, key, default_value);
|
||||
|
||||
exit:
|
||||
|
@ -121,4 +133,4 @@ dict___reversed__(PyDictObject *self, PyObject *Py_UNUSED(ignored))
|
|||
{
|
||||
return dict___reversed___impl(self);
|
||||
}
|
||||
/*[clinic end generated code: output=193e08cb8099fe22 input=a9049054013a1b77]*/
|
||||
/*[clinic end generated code: output=12c21ce3552d9617 input=a9049054013a1b77]*/
|
||||
|
|
7
Objects/clinic/enumobject.c.h
generated
7
Objects/clinic/enumobject.c.h
generated
|
@ -58,14 +58,13 @@ reversed_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
|
|||
!_PyArg_NoKeywords("reversed", kwargs)) {
|
||||
goto exit;
|
||||
}
|
||||
if (!PyArg_UnpackTuple(args, "reversed",
|
||||
1, 1,
|
||||
&seq)) {
|
||||
if (!_PyArg_CheckPositional("reversed", PyTuple_GET_SIZE(args), 1, 1)) {
|
||||
goto exit;
|
||||
}
|
||||
seq = PyTuple_GET_ITEM(args, 0);
|
||||
return_value = reversed_new_impl(type, seq);
|
||||
|
||||
exit:
|
||||
return return_value;
|
||||
}
|
||||
/*[clinic end generated code: output=9008c36999c57218 input=a9049054013a1b77]*/
|
||||
/*[clinic end generated code: output=831cec3db0e987c9 input=a9049054013a1b77]*/
|
||||
|
|
20
Objects/clinic/floatobject.c.h
generated
20
Objects/clinic/floatobject.c.h
generated
|
@ -58,11 +58,14 @@ float___round__(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
|
|||
PyObject *return_value = NULL;
|
||||
PyObject *o_ndigits = NULL;
|
||||
|
||||
if (!_PyArg_UnpackStack(args, nargs, "__round__",
|
||||
0, 1,
|
||||
&o_ndigits)) {
|
||||
if (!_PyArg_CheckPositional("__round__", nargs, 0, 1)) {
|
||||
goto exit;
|
||||
}
|
||||
if (nargs < 1) {
|
||||
goto skip_optional;
|
||||
}
|
||||
o_ndigits = args[0];
|
||||
skip_optional:
|
||||
return_value = float___round___impl(self, o_ndigits);
|
||||
|
||||
exit:
|
||||
|
@ -173,11 +176,14 @@ float_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
|
|||
!_PyArg_NoKeywords("float", kwargs)) {
|
||||
goto exit;
|
||||
}
|
||||
if (!PyArg_UnpackTuple(args, "float",
|
||||
0, 1,
|
||||
&x)) {
|
||||
if (!_PyArg_CheckPositional("float", PyTuple_GET_SIZE(args), 0, 1)) {
|
||||
goto exit;
|
||||
}
|
||||
if (PyTuple_GET_SIZE(args) < 1) {
|
||||
goto skip_optional;
|
||||
}
|
||||
x = PyTuple_GET_ITEM(args, 0);
|
||||
skip_optional:
|
||||
return_value = float_new_impl(type, x);
|
||||
|
||||
exit:
|
||||
|
@ -345,4 +351,4 @@ float___format__(PyObject *self, PyObject *arg)
|
|||
exit:
|
||||
return return_value;
|
||||
}
|
||||
/*[clinic end generated code: output=2631a60701a8f7d4 input=a9049054013a1b77]*/
|
||||
/*[clinic end generated code: output=c183029d87dd41fa input=a9049054013a1b77]*/
|
||||
|
|
11
Objects/clinic/listobject.c.h
generated
11
Objects/clinic/listobject.c.h
generated
|
@ -289,11 +289,14 @@ list___init__(PyObject *self, PyObject *args, PyObject *kwargs)
|
|||
!_PyArg_NoKeywords("list", kwargs)) {
|
||||
goto exit;
|
||||
}
|
||||
if (!PyArg_UnpackTuple(args, "list",
|
||||
0, 1,
|
||||
&iterable)) {
|
||||
if (!_PyArg_CheckPositional("list", PyTuple_GET_SIZE(args), 0, 1)) {
|
||||
goto exit;
|
||||
}
|
||||
if (PyTuple_GET_SIZE(args) < 1) {
|
||||
goto skip_optional;
|
||||
}
|
||||
iterable = PyTuple_GET_ITEM(args, 0);
|
||||
skip_optional:
|
||||
return_value = list___init___impl((PyListObject *)self, iterable);
|
||||
|
||||
exit:
|
||||
|
@ -335,4 +338,4 @@ list___reversed__(PyListObject *self, PyObject *Py_UNUSED(ignored))
|
|||
{
|
||||
return list___reversed___impl(self);
|
||||
}
|
||||
/*[clinic end generated code: output=1f641f5aef3f886f input=a9049054013a1b77]*/
|
||||
/*[clinic end generated code: output=4a835f9880a72273 input=a9049054013a1b77]*/
|
||||
|
|
11
Objects/clinic/tupleobject.c.h
generated
11
Objects/clinic/tupleobject.c.h
generated
|
@ -81,11 +81,14 @@ tuple_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
|
|||
!_PyArg_NoKeywords("tuple", kwargs)) {
|
||||
goto exit;
|
||||
}
|
||||
if (!PyArg_UnpackTuple(args, "tuple",
|
||||
0, 1,
|
||||
&iterable)) {
|
||||
if (!_PyArg_CheckPositional("tuple", PyTuple_GET_SIZE(args), 0, 1)) {
|
||||
goto exit;
|
||||
}
|
||||
if (PyTuple_GET_SIZE(args) < 1) {
|
||||
goto skip_optional;
|
||||
}
|
||||
iterable = PyTuple_GET_ITEM(args, 0);
|
||||
skip_optional:
|
||||
return_value = tuple_new_impl(type, iterable);
|
||||
|
||||
exit:
|
||||
|
@ -108,4 +111,4 @@ tuple___getnewargs__(PyTupleObject *self, PyObject *Py_UNUSED(ignored))
|
|||
{
|
||||
return tuple___getnewargs___impl(self);
|
||||
}
|
||||
/*[clinic end generated code: output=5312868473a41cfe input=a9049054013a1b77]*/
|
||||
/*[clinic end generated code: output=56fab9b7368aba49 input=a9049054013a1b77]*/
|
||||
|
|
29
Objects/clinic/unicodeobject.c.h
generated
29
Objects/clinic/unicodeobject.c.h
generated
|
@ -546,11 +546,14 @@ unicode_strip(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
|
|||
PyObject *return_value = NULL;
|
||||
PyObject *chars = Py_None;
|
||||
|
||||
if (!_PyArg_UnpackStack(args, nargs, "strip",
|
||||
0, 1,
|
||||
&chars)) {
|
||||
if (!_PyArg_CheckPositional("strip", nargs, 0, 1)) {
|
||||
goto exit;
|
||||
}
|
||||
if (nargs < 1) {
|
||||
goto skip_optional;
|
||||
}
|
||||
chars = args[0];
|
||||
skip_optional:
|
||||
return_value = unicode_strip_impl(self, chars);
|
||||
|
||||
exit:
|
||||
|
@ -577,11 +580,14 @@ unicode_lstrip(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
|
|||
PyObject *return_value = NULL;
|
||||
PyObject *chars = NULL;
|
||||
|
||||
if (!_PyArg_UnpackStack(args, nargs, "lstrip",
|
||||
0, 1,
|
||||
&chars)) {
|
||||
if (!_PyArg_CheckPositional("lstrip", nargs, 0, 1)) {
|
||||
goto exit;
|
||||
}
|
||||
if (nargs < 1) {
|
||||
goto skip_optional;
|
||||
}
|
||||
chars = args[0];
|
||||
skip_optional:
|
||||
return_value = unicode_lstrip_impl(self, chars);
|
||||
|
||||
exit:
|
||||
|
@ -608,11 +614,14 @@ unicode_rstrip(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
|
|||
PyObject *return_value = NULL;
|
||||
PyObject *chars = NULL;
|
||||
|
||||
if (!_PyArg_UnpackStack(args, nargs, "rstrip",
|
||||
0, 1,
|
||||
&chars)) {
|
||||
if (!_PyArg_CheckPositional("rstrip", nargs, 0, 1)) {
|
||||
goto exit;
|
||||
}
|
||||
if (nargs < 1) {
|
||||
goto skip_optional;
|
||||
}
|
||||
chars = args[0];
|
||||
skip_optional:
|
||||
return_value = unicode_rstrip_impl(self, chars);
|
||||
|
||||
exit:
|
||||
|
@ -1098,4 +1107,4 @@ unicode_sizeof(PyObject *self, PyObject *Py_UNUSED(ignored))
|
|||
{
|
||||
return unicode_sizeof_impl(self);
|
||||
}
|
||||
/*[clinic end generated code: output=73ad9670e00a2490 input=a9049054013a1b77]*/
|
||||
/*[clinic end generated code: output=087ff163a10505ae input=a9049054013a1b77]*/
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue