diff options
author | Raymond Hettinger <python@rcn.com> | 2008-06-11 12:39:09 +0000 |
---|---|---|
committer | Raymond Hettinger <python@rcn.com> | 2008-06-11 12:39:09 +0000 |
commit | 6fbfb481b82d101902bb20c17d9d42cd32beb160 (patch) | |
tree | c93fb97421c9cd1ece2e4d71891df76a20b9f55d /Modules/_heapqmodule.c | |
parent | e605e4f09a691aa68ddd6642f52afde221085e25 (diff) | |
download | cpython-git-6fbfb481b82d101902bb20c17d9d42cd32beb160.tar.gz |
Optimize previous checkin for heapq.
Diffstat (limited to 'Modules/_heapqmodule.c')
-rw-r--r-- | Modules/_heapqmodule.c | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/Modules/_heapqmodule.c b/Modules/_heapqmodule.c index 8edf626eff..4fd0dd51ef 100644 --- a/Modules/_heapqmodule.c +++ b/Modules/_heapqmodule.c @@ -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) |