summaryrefslogtreecommitdiff
path: root/Python/clinic/context.c.h
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2019-01-11 18:01:42 +0200
committerGitHub <noreply@github.com>2019-01-11 18:01:42 +0200
commit2a39d251f07d4c620e3b9a1848e3d1eb3067be64 (patch)
tree23c1e8e63e57945fab6127d31800b7578795e14b /Python/clinic/context.c.h
parent4fa9591025b6a098f3d6402e5413ee6740ede6c5 (diff)
downloadcpython-git-2a39d251f07d4c620e3b9a1848e3d1eb3067be64.tar.gz
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/clinic/context.c.h')
-rw-r--r--Python/clinic/context.c.h21
1 files changed, 14 insertions, 7 deletions
diff --git a/Python/clinic/context.c.h b/Python/clinic/context.c.h
index 32b1883ebe..bbe19db1bd 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]*/