Commit 1ae77b00 authored by Robert Bradshaw's avatar Robert Bradshaw

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.
parent 50bab2d6
......@@ -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(
"}")
......
......@@ -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):
......
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