Skip to content

Commit 093119e

Browse files
committed
Argument Clinic: Use METH_FASTCALL for boring positionals
Issue python#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().
1 parent fe54dd8 commit 093119e

1 file changed

Lines changed: 25 additions & 9 deletions

File tree

Tools/clinic/clinic.py

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -825,16 +825,32 @@ def insert_keywords(s):
825825
# and nothing but normal objects:
826826
# PyArg_UnpackTuple!
827827

828-
flags = "METH_VARARGS"
829-
parser_prototype = parser_prototype_varargs
828+
if not new_or_init:
829+
flags = "METH_FASTCALL"
830+
parser_prototype = parser_prototype_fastcall
830831

831-
parser_definition = parser_body(parser_prototype, normalize_snippet("""
832-
if (!PyArg_UnpackTuple(args, "{name}",
833-
{unpack_min}, {unpack_max},
834-
{parse_arguments})) {{
835-
goto exit;
836-
}}
837-
""", indent=4))
832+
parser_definition = parser_body(parser_prototype, normalize_snippet("""
833+
if (!_PyArg_UnpackStack(args, nargs, "{name}",
834+
{unpack_min}, {unpack_max},
835+
{parse_arguments})) {{
836+
goto exit;
837+
}}
838+
839+
if ({self_type_check}!_PyArg_NoStackKeywords("{name}", kwnames)) {{
840+
goto exit;
841+
}}
842+
""", indent=4))
843+
else:
844+
flags = "METH_VARARGS"
845+
parser_prototype = parser_prototype_varargs
846+
847+
parser_definition = parser_body(parser_prototype, normalize_snippet("""
848+
if (!PyArg_UnpackTuple(args, "{name}",
849+
{unpack_min}, {unpack_max},
850+
{parse_arguments})) {{
851+
goto exit;
852+
}}
853+
""", indent=4))
838854

839855
elif positional:
840856
if not new_or_init:

0 commit comments

Comments
 (0)