diff options
author | Victor Stinner <victor.stinner@gmail.com> | 2017-01-17 01:35:41 (GMT) |
---|---|---|
committer | Victor Stinner <victor.stinner@gmail.com> | 2017-01-17 01:35:41 (GMT) |
commit | 093119e4eb8424451ef24a5a5a3ce9881d77abd5 (patch) | |
tree | cfd621572f359d8e9ca23d74b4b262943e42a4e3 /Tools/clinic | |
parent | fe54dd8a08b171c20bafe0759c17464a2642030d (diff) | |
download | cpython-093119e4eb8424451ef24a5a5a3ce9881d77abd5.zip cpython-093119e4eb8424451ef24a5a5a3ce9881d77abd5.tar.gz cpython-093119e4eb8424451ef24a5a5a3ce9881d77abd5.tar.bz2 |
Argument Clinic: Use METH_FASTCALL for boring positionals
Issue #29286. Use METH_FASTCALL calling convention instead of METH_VARARGS to
parse "boring" position arguments. METH_FASTCALL is faster since it avoids the
creation of a temporary tuple to pass positional arguments.
Replace PyArg_UnpackTuple() with _PyArg_UnpackStack()+_PyArg_NoStackKeywords().
Diffstat (limited to 'Tools/clinic')
-rwxr-xr-x | Tools/clinic/clinic.py | 34 |
1 files changed, 25 insertions, 9 deletions
diff --git a/Tools/clinic/clinic.py b/Tools/clinic/clinic.py index 7c4b388..894d1c5 100755 --- a/Tools/clinic/clinic.py +++ b/Tools/clinic/clinic.py @@ -825,16 +825,32 @@ class CLanguage(Language): # and nothing but normal objects: # PyArg_UnpackTuple! - flags = "METH_VARARGS" - parser_prototype = parser_prototype_varargs + if not new_or_init: + flags = "METH_FASTCALL" + parser_prototype = parser_prototype_fastcall - parser_definition = parser_body(parser_prototype, normalize_snippet(""" - if (!PyArg_UnpackTuple(args, "{name}", - {unpack_min}, {unpack_max}, - {parse_arguments})) {{ - goto exit; - }} - """, indent=4)) + parser_definition = parser_body(parser_prototype, normalize_snippet(""" + if (!_PyArg_UnpackStack(args, nargs, "{name}", + {unpack_min}, {unpack_max}, + {parse_arguments})) {{ + goto exit; + }} + + if ({self_type_check}!_PyArg_NoStackKeywords("{name}", kwnames)) {{ + goto exit; + }} + """, indent=4)) + else: + flags = "METH_VARARGS" + parser_prototype = parser_prototype_varargs + + parser_definition = parser_body(parser_prototype, normalize_snippet(""" + if (!PyArg_UnpackTuple(args, "{name}", + {unpack_min}, {unpack_max}, + {parse_arguments})) {{ + goto exit; + }} + """, indent=4)) elif positional: if not new_or_init: |