mirror of
https://github.com/python/cpython.git
synced 2025-08-04 17:08:35 +00:00
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.
This commit is contained in:
parent
4fa9591025
commit
2a39d251f0
30 changed files with 561 additions and 408 deletions
|
@ -643,18 +643,6 @@ class CLanguage(Language):
|
|||
f.return_converter.type == 'PyObject *')
|
||||
|
||||
positional = parameters and parameters[-1].is_positional_only()
|
||||
all_boring_objects = False # yes, this will be false if there are 0 parameters, it's fine
|
||||
first_optional = len(parameters)
|
||||
for i, p in enumerate(parameters):
|
||||
c = p.converter
|
||||
if type(c) != object_converter:
|
||||
break
|
||||
if c.format_unit != 'O':
|
||||
break
|
||||
if p.default is not unspecified:
|
||||
first_optional = min(first_optional, i)
|
||||
else:
|
||||
all_boring_objects = True
|
||||
|
||||
new_or_init = f.kind in (METHOD_NEW, METHOD_INIT)
|
||||
|
||||
|
@ -827,34 +815,6 @@ class CLanguage(Language):
|
|||
|
||||
parser_definition = parser_body(parser_prototype, ' {option_group_parsing}')
|
||||
|
||||
elif positional and all_boring_objects:
|
||||
# positional-only, but no option groups,
|
||||
# and nothing but normal objects:
|
||||
# PyArg_UnpackTuple!
|
||||
|
||||
if not new_or_init:
|
||||
flags = "METH_FASTCALL"
|
||||
parser_prototype = parser_prototype_fastcall
|
||||
|
||||
parser_definition = parser_body(parser_prototype, normalize_snippet("""
|
||||
if (!_PyArg_UnpackStack(args, nargs, "{name}",
|
||||
{unpack_min}, {unpack_max},
|
||||
{parse_arguments})) {{
|
||||
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:
|
||||
# positional-only, but no option groups
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue