From 9c39e3e7b2c86f9ab2af3242bd83fcf1b863861e Mon Sep 17 00:00:00 2001 From: Carl Witty Date: Mon, 26 Jul 2010 23:25:00 -0700 Subject: [PATCH] trac #561: fixed major performance bug in special functions (by not generating Python versions and letting PyType_Ready() do it instead; details are on the trac ticket) --- Cython/Compiler/Code.py | 9 ++++++++- Cython/Compiler/Nodes.py | 2 +- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/Cython/Compiler/Code.py b/Cython/Compiler/Code.py index 368d0ebf..505fd216 100644 --- a/Cython/Compiler/Code.py +++ b/Cython/Compiler/Code.py @@ -1230,7 +1230,14 @@ class CCodeWriter(object): # code = "((PyObject*)%s)" % code self.put_init_to_py_none(code, entry.type, nanny) - def put_pymethoddef(self, entry, term): + def put_pymethoddef(self, entry, term, allow_skip=True): + if entry.is_special or entry.name in ['__getitem__', '__setslice__', '__delslice__', '__setitem__', '__delitem__', '__getattr__', '__getattribute__', '__setattr__', '__delattr__']: + if entry.name not in ['__next__', '__getreadbuffer__', '__getwritebuffer__', '__getsegcount__', '__getcharbuffer__', '__getbuffer__', '__releasebuffer__']: + # Python's typeobject.c will automatically fill in our slot + # in add_operators() (called by PyType_Ready) with a value + # that's better than ours. + if allow_skip: + return from TypeSlots import method_coexist if entry.doc: doc_code = entry.doc_cname diff --git a/Cython/Compiler/Nodes.py b/Cython/Compiler/Nodes.py index 97a1b80a..05ce3c96 100644 --- a/Cython/Compiler/Nodes.py +++ b/Cython/Compiler/Nodes.py @@ -2239,7 +2239,7 @@ class DefNode(FuncDefNode): code.put( "static PyMethodDef %s = " % self.entry.pymethdef_cname) - code.put_pymethoddef(self.entry, ";") + code.put_pymethoddef(self.entry, ";", allow_skip=False) code.putln("%s {" % header) def generate_argument_declarations(self, env, code): -- 2.26.2