Allow trivial __cinit__ that ignores __init__ values for speed.
authorRobert Bradshaw <robertwb@math.washington.edu>
Thu, 17 Jan 2008 14:00:27 +0000 (06:00 -0800)
committerRobert Bradshaw <robertwb@math.washington.edu>
Thu, 17 Jan 2008 14:00:27 +0000 (06:00 -0800)
The signatures are no longer required to match if the only argument to __cinit__ is self.

Cython/Compiler/ModuleNode.py
Cython/Compiler/Nodes.py

index c9f60433987d61a0815f8bef4af558c8aaf935d0..8332828684263b6122af9c5376337c63a4ddfd85 100644 (file)
@@ -656,9 +656,13 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
                 code.put_init_var_to_py_none(entry, "p->%s")
         entry = scope.lookup_here("__new__")
         if entry:
+            if entry.trivial_signature:
+                cinit_args = "o, %s, NULL" % Naming.empty_tuple
+            else:
+                cinit_args = "o, a, k"
             code.putln(
-                "if (%s(o, a, k) < 0) {" % 
-                    entry.func_cname)
+                "if (%s(%s) < 0) {" % 
+                    (entry.func_cname, cinit_args))
             code.put_decref_clear("o", py_object_type);
             code.putln(
                 "}")
index 391e613380d11b903a9903c0f51fb4b3c6e388cd..22f7696216697ec4352f4a73b782a158974306ab 100644 (file)
@@ -977,6 +977,8 @@ class DefNode(FuncDefNode):
                 elif len(self.args) == 2:
                     if self.args[1].default is None and not self.args[1].kw_only:
                         self.entry.signature = TypeSlots.ibinaryfunc
+        elif self.entry.is_special:
+            self.entry.trivial_signature = len(self.args) == 1 and not (self.star_arg or self.starstar_arg)
         sig = self.entry.signature
         nfixed = sig.num_fixed_args()
         for i in range(nfixed):