From: Stefan Behnel Date: Sat, 2 Feb 2008 11:35:05 +0000 (+0100) Subject: Cython could generate useless argument tuple parsing code for functions with required... X-Git-Tag: 0.9.6.14~29^2~37^2~8 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=94aede41f4099540af41fa0e5e0d61b2396a0137;p=cython.git Cython could generate useless argument tuple parsing code for functions with required kw-only args --- diff --git a/Cython/Compiler/Nodes.py b/Cython/Compiler/Nodes.py index f13df2ab..69feca9c 100644 --- a/Cython/Compiler/Nodes.py +++ b/Cython/Compiler/Nodes.py @@ -1260,16 +1260,19 @@ class DefNode(FuncDefNode): our_error_label = code.error_label end_label = code.new_label() # Unpack inplace if it's simple - has_self_arg = len(self.args) > 0 and self.args[0].is_self_arg - if self.num_required_args == len(positional_args) + has_self_arg: + min_positional_args = self.num_required_args - self.num_required_kw_args + 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)" % ( - Naming.args_cname, len(positional_args)) + Naming.args_cname, max_positional_args) else: 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, - len(positional_args)) + max_positional_args) code.putln( 'if (likely(!%s) && %s) {' % (Naming.kwds_cname, count_cond)) i = 0