Commit 94aede41 authored by Stefan Behnel's avatar Stefan Behnel

Cython could generate useless argument tuple parsing code for functions with required kw-only args

parent 20ad25cf
...@@ -1260,16 +1260,19 @@ class DefNode(FuncDefNode): ...@@ -1260,16 +1260,19 @@ class DefNode(FuncDefNode):
our_error_label = code.error_label our_error_label = code.error_label
end_label = code.new_label() end_label = code.new_label()
# Unpack inplace if it's simple # Unpack inplace if it's simple
has_self_arg = len(self.args) > 0 and self.args[0].is_self_arg min_positional_args = self.num_required_args - self.num_required_kw_args
if self.num_required_args == len(positional_args) + has_self_arg: max_positional_args = len(positional_args)
if len(self.args) > 0 and self.args[0].is_self_arg:
min_positional_args -= 1
if max_positional_args == min_positional_args:
count_cond = "likely(PyTuple_GET_SIZE(%s) == %s)" % ( count_cond = "likely(PyTuple_GET_SIZE(%s) == %s)" % (
Naming.args_cname, len(positional_args)) Naming.args_cname, max_positional_args)
else: else:
count_cond = "likely(%s <= PyTuple_GET_SIZE(%s)) && likely(PyTuple_GET_SIZE(%s) <= %s)" % ( count_cond = "likely(%s <= PyTuple_GET_SIZE(%s)) && likely(PyTuple_GET_SIZE(%s) <= %s)" % (
self.num_required_args - has_self_arg, min_positional_args,
Naming.args_cname, Naming.args_cname,
Naming.args_cname, Naming.args_cname,
len(positional_args)) max_positional_args)
code.putln( code.putln(
'if (likely(!%s) && %s) {' % (Naming.kwds_cname, count_cond)) 'if (likely(!%s) && %s) {' % (Naming.kwds_cname, count_cond))
i = 0 i = 0
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment