From 25f8180ebf16181c3e30cc789502cb4d086f5272 Mon Sep 17 00:00:00 2001 From: Lisandro Dalcin Date: Fri, 19 Jun 2009 14:13:14 -0300 Subject: [PATCH] get rid of string comparisons in classmethod utility code --- Cython/Compiler/ModuleNode.py | 3 +-- Cython/Compiler/Symtab.py | 10 ++++++++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/Cython/Compiler/ModuleNode.py b/Cython/Compiler/ModuleNode.py index 63b72a3a..c400499f 100644 --- a/Cython/Compiler/ModuleNode.py +++ b/Cython/Compiler/ModuleNode.py @@ -588,8 +588,6 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode): code.putln('static char %s[] = "%s";' % ( env.doc_cname, escape_byte_string(docstr))) - env.use_utility_code(streq_utility_code) - # XXX this is a mess for utility_code in PyrexTypes.c_int_from_py_function.specialize_list: env.use_utility_code(utility_code) @@ -1556,6 +1554,7 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode): code.putln("static void %s(void); /*proto*/" % Naming.fileinit_cname) def generate_import_star(self, env, code): + env.use_utility_code(streq_utility_code) code.putln() code.putln("char* %s_type_names[] = {" % Naming.import_star) for name, entry in env.entries.items(): diff --git a/Cython/Compiler/Symtab.py b/Cython/Compiler/Symtab.py index 2e5415ef..8c96a208 100644 --- a/Cython/Compiler/Symtab.py +++ b/Cython/Compiler/Symtab.py @@ -1583,8 +1583,14 @@ static PyObject* __Pyx_Method_ClassMethod(PyObject *method); /*proto*/ impl = """ static PyObject* __Pyx_Method_ClassMethod(PyObject *method) { /* It appears that PyMethodDescr_Type is not anywhere exposed in the Python/C API */ - /* if (!PyObject_TypeCheck(method, &PyMethodDescr_Type)) { */ - if (__Pyx_StrEq(Py_TYPE(method)->tp_name, "method_descriptor")) { /* cdef classes */ + static PyTypeObject *methoddescr_type = NULL; + if (methoddescr_type == NULL) { + PyObject *meth = __Pyx_GetAttrString((PyObject*)&PyList_Type, "append"); + if (!meth) return NULL; + methoddescr_type = Py_TYPE(meth); + Py_DECREF(meth); + } + if (PyObject_TypeCheck(method, methoddescr_type)) { /* cdef classes */ PyMethodDescrObject *descr = (PyMethodDescrObject *)method; return PyDescr_NewClassMethod(descr->d_type, descr->d_method); } -- 2.26.2