Cython could generate useless argument tuple parsing code for functions with required...
authorStefan Behnel <scoder@users.berlios.de>
Sat, 2 Feb 2008 11:35:05 +0000 (12:35 +0100)
committerStefan Behnel <scoder@users.berlios.de>
Sat, 2 Feb 2008 11:35:05 +0000 (12:35 +0100)
Cython/Compiler/Nodes.py

index f13df2abdf498b1672dcd47aa450a65278a77ce8..69feca9cfab7bdbc066db9a8e5c71e5f66c5755f 100644 (file)
@@ -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