]> granicus.if.org Git - python/commitdiff
Optimize previous checkin for heapq.
authorRaymond Hettinger <python@rcn.com>
Wed, 11 Jun 2008 12:39:09 +0000 (12:39 +0000)
committerRaymond Hettinger <python@rcn.com>
Wed, 11 Jun 2008 12:39:09 +0000 (12:39 +0000)
Modules/_heapqmodule.c

index 8edf626effd69aa24564afd40c5b03ce8e9d147b..4fd0dd51ef70bcbda4c92c2d546a9d9836a3b6ec 100644 (file)
@@ -17,8 +17,14 @@ static int
 cmp_lt(PyObject *x, PyObject *y)
 {
        int cmp;
+       static PyObject *lt = NULL;
 
-       if (PyObject_HasAttrString(x, "__lt__"))
+       if (lt == NULL) {
+               lt = PyString_FromString("__lt__");
+               if (lt == NULL)
+                       return -1;
+       }
+       if (PyObject_HasAttr(x, lt))
                return PyObject_RichCompareBool(x, y, Py_LT);
        cmp = PyObject_RichCompareBool(y, x, Py_LE);
        if (cmp != -1)