get rid of string comparisons in classmethod utility code
authorLisandro Dalcin <dalcinl@gmail.com>
Fri, 19 Jun 2009 17:13:14 +0000 (14:13 -0300)
committerLisandro Dalcin <dalcinl@gmail.com>
Fri, 19 Jun 2009 17:13:14 +0000 (14:13 -0300)
Cython/Compiler/ModuleNode.py
Cython/Compiler/Symtab.py

index 63b72a3a2b88c2a76d0b51a2fdc0550d38fecca9..c400499f7bf5abf95062d380962acd0c2edbfcd3 100644 (file)
@@ -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():
index 2e5415ef04fecd5961b8ae0bbd69ad99f18cf637..8c96a208f205a2f127c0ddd00aba24d36077b1d7 100644 (file)
@@ -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);
     }