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 /Python | |
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 'Python')
-rw-r--r-- | Python/clinic/bltinmodule.c.h | 87 | ||||
-rw-r--r-- | Python/clinic/context.c.h | 21 | ||||
-rw-r--r-- | Python/clinic/import.c.h | 12 | ||||
-rw-r--r-- | Python/clinic/sysmodule.c.h | 18 |
4 files changed, 89 insertions, 49 deletions
diff --git a/Python/clinic/bltinmodule.c.h b/Python/clinic/bltinmodule.c.h index 68d8dcc..1b82f77 100644 --- a/Python/clinic/bltinmodule.c.h +++ b/Python/clinic/bltinmodule.c.h @@ -217,11 +217,11 @@ builtin_divmod(PyObject *module, PyObject *const *args, Py_ssize_t nargs) PyObject *x; PyObject *y; - if (!_PyArg_UnpackStack(args, nargs, "divmod", - 2, 2, - &x, &y)) { + if (!_PyArg_CheckPositional("divmod", nargs, 2, 2)) { goto exit; } + x = args[0]; + y = args[1]; return_value = builtin_divmod_impl(module, x, y); exit: @@ -255,11 +255,19 @@ builtin_eval(PyObject *module, PyObject *const *args, Py_ssize_t nargs) PyObject *globals = Py_None; PyObject *locals = Py_None; - if (!_PyArg_UnpackStack(args, nargs, "eval", - 1, 3, - &source, &globals, &locals)) { + if (!_PyArg_CheckPositional("eval", nargs, 1, 3)) { goto exit; } + source = args[0]; + if (nargs < 2) { + goto skip_optional; + } + globals = args[1]; + if (nargs < 3) { + goto skip_optional; + } + locals = args[2]; +skip_optional: return_value = builtin_eval_impl(module, source, globals, locals); exit: @@ -293,11 +301,19 @@ builtin_exec(PyObject *module, PyObject *const *args, Py_ssize_t nargs) PyObject *globals = Py_None; PyObject *locals = Py_None; - if (!_PyArg_UnpackStack(args, nargs, "exec", - 1, 3, - &source, &globals, &locals)) { + if (!_PyArg_CheckPositional("exec", nargs, 1, 3)) { goto exit; } + source = args[0]; + if (nargs < 2) { + goto skip_optional; + } + globals = args[1]; + if (nargs < 3) { + goto skip_optional; + } + locals = args[2]; +skip_optional: return_value = builtin_exec_impl(module, source, globals, locals); exit: @@ -346,11 +362,11 @@ builtin_hasattr(PyObject *module, PyObject *const *args, Py_ssize_t nargs) PyObject *obj; PyObject *name; - if (!_PyArg_UnpackStack(args, nargs, "hasattr", - 2, 2, - &obj, &name)) { + if (!_PyArg_CheckPositional("hasattr", nargs, 2, 2)) { goto exit; } + obj = args[0]; + name = args[1]; return_value = builtin_hasattr_impl(module, obj, name); exit: @@ -392,11 +408,12 @@ builtin_setattr(PyObject *module, PyObject *const *args, Py_ssize_t nargs) PyObject *name; PyObject *value; - if (!_PyArg_UnpackStack(args, nargs, "setattr", - 3, 3, - &obj, &name, &value)) { + if (!_PyArg_CheckPositional("setattr", nargs, 3, 3)) { goto exit; } + obj = args[0]; + name = args[1]; + value = args[2]; return_value = builtin_setattr_impl(module, obj, name, value); exit: @@ -424,11 +441,11 @@ builtin_delattr(PyObject *module, PyObject *const *args, Py_ssize_t nargs) PyObject *obj; PyObject *name; - if (!_PyArg_UnpackStack(args, nargs, "delattr", - 2, 2, - &obj, &name)) { + if (!_PyArg_CheckPositional("delattr", nargs, 2, 2)) { goto exit; } + obj = args[0]; + name = args[1]; return_value = builtin_delattr_impl(module, obj, name); exit: @@ -534,11 +551,16 @@ builtin_pow(PyObject *module, PyObject *const *args, Py_ssize_t nargs) PyObject *y; PyObject *z = Py_None; - if (!_PyArg_UnpackStack(args, nargs, "pow", - 2, 3, - &x, &y, &z)) { + if (!_PyArg_CheckPositional("pow", nargs, 2, 3)) { goto exit; } + x = args[0]; + y = args[1]; + if (nargs < 3) { + goto skip_optional; + } + z = args[2]; +skip_optional: return_value = builtin_pow_impl(module, x, y, z); exit: @@ -569,11 +591,14 @@ builtin_input(PyObject *module, PyObject *const *args, Py_ssize_t nargs) PyObject *return_value = NULL; PyObject *prompt = NULL; - if (!_PyArg_UnpackStack(args, nargs, "input", - 0, 1, - &prompt)) { + if (!_PyArg_CheckPositional("input", nargs, 0, 1)) { goto exit; } + if (nargs < 1) { + goto skip_optional; + } + prompt = args[0]; +skip_optional: return_value = builtin_input_impl(module, prompt); exit: @@ -684,11 +709,11 @@ builtin_isinstance(PyObject *module, PyObject *const *args, Py_ssize_t nargs) PyObject *obj; PyObject *class_or_tuple; - if (!_PyArg_UnpackStack(args, nargs, "isinstance", - 2, 2, - &obj, &class_or_tuple)) { + if (!_PyArg_CheckPositional("isinstance", nargs, 2, 2)) { goto exit; } + obj = args[0]; + class_or_tuple = args[1]; return_value = builtin_isinstance_impl(module, obj, class_or_tuple); exit: @@ -719,14 +744,14 @@ builtin_issubclass(PyObject *module, PyObject *const *args, Py_ssize_t nargs) PyObject *cls; PyObject *class_or_tuple; - if (!_PyArg_UnpackStack(args, nargs, "issubclass", - 2, 2, - &cls, &class_or_tuple)) { + if (!_PyArg_CheckPositional("issubclass", nargs, 2, 2)) { goto exit; } + cls = args[0]; + class_or_tuple = args[1]; return_value = builtin_issubclass_impl(module, cls, class_or_tuple); exit: return return_value; } -/*[clinic end generated code: output=11b5cd918bd7eb18 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=54e5e33dcc2659e0 input=a9049054013a1b77]*/ diff --git a/Python/clinic/context.c.h b/Python/clinic/context.c.h index 32b1883..bbe19db 100644 --- a/Python/clinic/context.c.h +++ b/Python/clinic/context.c.h @@ -25,11 +25,15 @@ _contextvars_Context_get(PyContext *self, PyObject *const *args, Py_ssize_t narg 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 = _contextvars_Context_get_impl(self, key, default_value); exit: @@ -134,11 +138,14 @@ _contextvars_ContextVar_get(PyContextVar *self, PyObject *const *args, Py_ssize_ PyObject *return_value = NULL; PyObject *default_value = NULL; - if (!_PyArg_UnpackStack(args, nargs, "get", - 0, 1, - &default_value)) { + if (!_PyArg_CheckPositional("get", nargs, 0, 1)) { goto exit; } + if (nargs < 1) { + goto skip_optional; + } + default_value = args[0]; +skip_optional: return_value = _contextvars_ContextVar_get_impl(self, default_value); exit: @@ -170,4 +177,4 @@ PyDoc_STRVAR(_contextvars_ContextVar_reset__doc__, #define _CONTEXTVARS_CONTEXTVAR_RESET_METHODDEF \ {"reset", (PyCFunction)_contextvars_ContextVar_reset, METH_O, _contextvars_ContextVar_reset__doc__}, -/*[clinic end generated code: output=9c93e22bcadbaa2b input=a9049054013a1b77]*/ +/*[clinic end generated code: output=67c3a8f76b6cf4e7 input=a9049054013a1b77]*/ diff --git a/Python/clinic/import.c.h b/Python/clinic/import.c.h index 783ed4e..9ee20fb 100644 --- a/Python/clinic/import.c.h +++ b/Python/clinic/import.c.h @@ -318,11 +318,15 @@ _imp_create_dynamic(PyObject *module, PyObject *const *args, Py_ssize_t nargs) PyObject *spec; PyObject *file = NULL; - if (!_PyArg_UnpackStack(args, nargs, "create_dynamic", - 1, 2, - &spec, &file)) { + if (!_PyArg_CheckPositional("create_dynamic", nargs, 1, 2)) { goto exit; } + spec = args[0]; + if (nargs < 2) { + goto skip_optional; + } + file = args[1]; +skip_optional: return_value = _imp_create_dynamic_impl(module, spec, file); exit: @@ -433,4 +437,4 @@ exit: #ifndef _IMP_EXEC_DYNAMIC_METHODDEF #define _IMP_EXEC_DYNAMIC_METHODDEF #endif /* !defined(_IMP_EXEC_DYNAMIC_METHODDEF) */ -/*[clinic end generated code: output=22062cee6e8ba7f3 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=2409b8feeafe7c4b input=a9049054013a1b77]*/ diff --git a/Python/clinic/sysmodule.c.h b/Python/clinic/sysmodule.c.h index 7370ab5..fc9794b 100644 --- a/Python/clinic/sysmodule.c.h +++ b/Python/clinic/sysmodule.c.h @@ -32,11 +32,12 @@ sys_excepthook(PyObject *module, PyObject *const *args, Py_ssize_t nargs) PyObject *value; PyObject *traceback; - if (!_PyArg_UnpackStack(args, nargs, "excepthook", - 3, 3, - &exctype, &value, &traceback)) { + if (!_PyArg_CheckPositional("excepthook", nargs, 3, 3)) { goto exit; } + exctype = args[0]; + value = args[1]; + traceback = args[2]; return_value = sys_excepthook_impl(module, exctype, value, traceback); exit: @@ -87,11 +88,14 @@ sys_exit(PyObject *module, PyObject *const *args, Py_ssize_t nargs) PyObject *return_value = NULL; PyObject *status = NULL; - if (!_PyArg_UnpackStack(args, nargs, "exit", - 0, 1, - &status)) { + if (!_PyArg_CheckPositional("exit", nargs, 0, 1)) { goto exit; } + if (nargs < 1) { + goto skip_optional; + } + status = args[0]; +skip_optional: return_value = sys_exit_impl(module, status); exit: @@ -1046,4 +1050,4 @@ sys_getandroidapilevel(PyObject *module, PyObject *Py_UNUSED(ignored)) #ifndef SYS_GETANDROIDAPILEVEL_METHODDEF #define SYS_GETANDROIDAPILEVEL_METHODDEF #endif /* !defined(SYS_GETANDROIDAPILEVEL_METHODDEF) */ -/*[clinic end generated code: output=6a5202e5bfe5e6bd input=a9049054013a1b77]*/ +/*[clinic end generated code: output=109787af3401cd27 input=a9049054013a1b77]*/ |