cpython: de90f3d06bc9 (original) (raw)
Mercurial > cpython
changeset 106178:de90f3d06bc9
Argument Clinic: Use METH_FASTCALL for positionals Issue #29286. Use METH_FASTCALL calling convention instead of METH_VARARGS to parse position arguments. METH_FASTCALL is faster since it avoids the creation of a temporary tuple to pass positional arguments. [#29286]
Victor Stinner victor.stinner@gmail.com | |
---|---|
date | Tue, 17 Jan 2017 01:42:54 +0100 |
parents | 38ab8572fde2 |
children | dea8922751a1 |
files | Tools/clinic/clinic.py |
diffstat | 1 files changed, 35 insertions(+), 17 deletions(-)[+] [-] Tools/clinic/clinic.py 52 |
line wrap: on
line diff
--- a/Tools/clinic/clinic.py +++ b/Tools/clinic/clinic.py @@ -705,16 +705,16 @@ class CLanguage(Language): {c_basename}({self_type}{self_name}, PyObject *args, PyObject *kwargs) """)
parser_prototype_varargs = normalize_snippet("""[](#l1.7)
static PyObject *[](#l1.8)
{c_basename}({self_type}{self_name}, PyObject *args)[](#l1.9)
""")[](#l1.10)
+ parser_prototype_fastcall = normalize_snippet(""" static PyObject * {c_basename}({self_type}{self_name}, PyObject **args, Py_ssize_t nargs, PyObject *kwnames) """)
parser_prototype_varargs = normalize_snippet("""[](#l1.17)
static PyObject *[](#l1.18)
{c_basename}({self_type}{self_name}, PyObject *args)[](#l1.19)
""")[](#l1.20)
- # parser_body_fields remembers the fields passed in to the # previous call to parser_body. this is used for an awful hack. parser_body_fields = () @@ -837,18 +837,36 @@ class CLanguage(Language): """, indent=4)) elif positional:
# positional-only, but no option groups[](#l1.29)
# we only need one call to PyArg_ParseTuple[](#l1.30)
flags = "METH_VARARGS"[](#l1.32)
parser_prototype = parser_prototype_varargs[](#l1.33)
parser_definition = parser_body(parser_prototype, normalize_snippet("""[](#l1.35)
if (!PyArg_ParseTuple(args, "{format_units}:{name}",[](#l1.36)
{parse_arguments})) {{[](#l1.37)
goto exit;[](#l1.38)
}}[](#l1.39)
""", indent=4))[](#l1.40)
if not new_or_init:[](#l1.41)
# positional-only, but no option groups[](#l1.42)
# we only need one call to _PyArg_ParseStack[](#l1.43)
flags = "METH_FASTCALL"[](#l1.45)
parser_prototype = parser_prototype_fastcall[](#l1.46)
parser_definition = parser_body(parser_prototype, normalize_snippet("""[](#l1.48)
if (!_PyArg_ParseStack(args, nargs, "{format_units}:{name}",[](#l1.49)
{parse_arguments})) {{[](#l1.50)
goto exit;[](#l1.51)
}}[](#l1.52)
if ({self_type_check}!_PyArg_NoStackKeywords("{name}", kwnames)) {{[](#l1.54)
goto exit;[](#l1.55)
}}[](#l1.56)
""", indent=4))[](#l1.57)
else:[](#l1.58)
# positional-only, but no option groups[](#l1.59)
# we only need one call to PyArg_ParseTuple[](#l1.60)
flags = "METH_VARARGS"[](#l1.62)
parser_prototype = parser_prototype_varargs[](#l1.63)
parser_definition = parser_body(parser_prototype, normalize_snippet("""[](#l1.65)
if (!PyArg_ParseTuple(args, "{format_units}:{name}",[](#l1.66)
{parse_arguments})) {{[](#l1.67)
goto exit;[](#l1.68)
}}[](#l1.69)
""", indent=4))[](#l1.70)