diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2019-01-11 16:01:42 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-01-11 16:01:42 (GMT) |
commit | 2a39d251f07d4c620e3b9a1848e3d1eb3067be64 (patch) | |
tree | 23c1e8e63e57945fab6127d31800b7578795e14b /Objects/clinic | |
parent | 4fa9591025b6a098f3d6402e5413ee6740ede6c5 (diff) | |
download | cpython-2a39d251f07d4c620e3b9a1848e3d1eb3067be64.zip cpython-2a39d251f07d4c620e3b9a1848e3d1eb3067be64.tar.gz cpython-2a39d251f07d4c620e3b9a1848e3d1eb3067be64.tar.bz2 |
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.
Diffstat (limited to 'Objects/clinic')
-rw-r--r-- | Objects/clinic/bytearrayobject.c.h | 29 | ||||
-rw-r--r-- | Objects/clinic/bytesobject.c.h | 29 | ||||
-rw-r--r-- | Objects/clinic/dictobject.c.h | 32 | ||||
-rw-r--r-- | Objects/clinic/enumobject.c.h | 7 | ||||
-rw-r--r-- | Objects/clinic/floatobject.c.h | 20 | ||||
-rw-r--r-- | Objects/clinic/listobject.c.h | 11 | ||||
-rw-r--r-- | Objects/clinic/tupleobject.c.h | 11 | ||||
-rw-r--r-- | Objects/clinic/unicodeobject.c.h | 29 |
8 files changed, 109 insertions, 59 deletions
diff --git a/Objects/clinic/bytearrayobject.c.h b/Objects/clinic/bytearrayobject.c.h index 2d7c742..a4669f5 100644 --- a/Objects/clinic/bytearrayobject.c.h +++ b/Objects/clinic/bytearrayobject.c.h @@ -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]*/ diff --git a/Objects/clinic/bytesobject.c.h b/Objects/clinic/bytesobject.c.h index 4e754d9..d75bbf1 100644 --- a/Objects/clinic/bytesobject.c.h +++ b/Objects/clinic/bytesobject.c.h @@ -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]*/ diff --git a/Objects/clinic/dictobject.c.h b/Objects/clinic/dictobject.c.h index 5db3a42..713781c 100644 --- a/Objects/clinic/dictobject.c.h +++ b/Objects/clinic/dictobject.c.h @@ -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]*/ diff --git a/Objects/clinic/enumobject.c.h b/Objects/clinic/enumobject.c.h index 0f05cf8..27da294 100644 --- a/Objects/clinic/enumobject.c.h +++ b/Objects/clinic/enumobject.c.h @@ -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]*/ diff --git a/Objects/clinic/floatobject.c.h b/Objects/clinic/floatobject.c.h index 741ca3b..4251d63 100644 --- a/Objects/clinic/floatobject.c.h +++ b/Objects/clinic/floatobject.c.h @@ -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]*/ diff --git a/Objects/clinic/listobject.c.h b/Objects/clinic/listobject.c.h index 3617458..447cdef 100644 --- a/Objects/clinic/listobject.c.h +++ b/Objects/clinic/listobject.c.h @@ -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]*/ diff --git a/Objects/clinic/tupleobject.c.h b/Objects/clinic/tupleobject.c.h index 0096f0c..fe2fae4 100644 --- a/Objects/clinic/tupleobject.c.h +++ b/Objects/clinic/tupleobject.c.h @@ -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]*/ diff --git a/Objects/clinic/unicodeobject.c.h b/Objects/clinic/unicodeobject.c.h index 21e54f1..3e40a62 100644 --- a/Objects/clinic/unicodeobject.c.h +++ b/Objects/clinic/unicodeobject.c.h @@ -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]*/ |