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:
Serhiy Storchaka 2019-01-11 18:01:42 +02:00 committed by GitHub
parent 4fa9591025
commit 2a39d251f0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
30 changed files with 561 additions and 408 deletions

View file

@ -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]*/