From 1ae77b00b51076eabdf60c11c9c6ff0c6cf06459 Mon Sep 17 00:00:00 2001 From: Robert Bradshaw Date: Thu, 17 Jan 2008 06:00:27 -0800 Subject: [PATCH] Allow trivial __cinit__ that ignores __init__ values for speed. The signatures are no longer required to match if the only argument to __cinit__ is self. --- Cython/Compiler/ModuleNode.py | 8 ++++++-- Cython/Compiler/Nodes.py | 2 ++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/Cython/Compiler/ModuleNode.py b/Cython/Compiler/ModuleNode.py index c9f60433..83328286 100644 --- a/Cython/Compiler/ModuleNode.py +++ b/Cython/Compiler/ModuleNode.py @@ -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( "}") diff --git a/Cython/Compiler/Nodes.py b/Cython/Compiler/Nodes.py index 391e6133..22f76962 100644 --- a/Cython/Compiler/Nodes.py +++ b/Cython/Compiler/Nodes.py @@ -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): -- 2.26.2