Optimize previous checkin for heapq.

This commit is contained in:
Raymond Hettinger 2008-06-11 12:39:09 +00:00
parent e605e4f09a
commit 6fbfb481b8
1 changed files with 7 additions and 1 deletions

View 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)