diff options
author | Raymond Hettinger <python@rcn.com> | 2010-09-05 05:26:10 (GMT) |
---|---|---|
committer | Raymond Hettinger <python@rcn.com> | 2010-09-05 05:26:10 (GMT) |
commit | db6b62e7569cea59e211a3d9d6a1a0e76e576e8c (patch) | |
tree | 86aacd62771a42327b1d74d632b3e3495d72835d /Modules/_heapqmodule.c | |
parent | 1784ff024985d827d15a51e6bd3960ca2355260f (diff) | |
download | cpython-db6b62e7569cea59e211a3d9d6a1a0e76e576e8c.zip cpython-db6b62e7569cea59e211a3d9d6a1a0e76e576e8c.tar.gz cpython-db6b62e7569cea59e211a3d9d6a1a0e76e576e8c.tar.bz2 |
Inline cmp_lt().
Diffstat (limited to 'Modules/_heapqmodule.c')
-rw-r--r-- | Modules/_heapqmodule.c | 26 |
1 files changed, 11 insertions, 15 deletions
diff --git a/Modules/_heapqmodule.c b/Modules/_heapqmodule.c index fd0ecac..1066f94 100644 --- a/Modules/_heapqmodule.c +++ b/Modules/_heapqmodule.c @@ -9,12 +9,6 @@ annotated by François Pinard, and converted to C by Raymond Hettinger. #include "Python.h" static int -cmp_lt(PyObject *x, PyObject *y) -{ - return PyObject_RichCompareBool(x, y, Py_LT); -} - -static int _siftdown(PyListObject *heap, Py_ssize_t startpos, Py_ssize_t pos) { PyObject *newitem, *parent; @@ -34,7 +28,7 @@ _siftdown(PyListObject *heap, Py_ssize_t startpos, Py_ssize_t pos) while (pos > startpos){ parentpos = (pos - 1) >> 1; parent = PyList_GET_ITEM(heap, parentpos); - cmp = cmp_lt(newitem, parent); + cmp = PyObject_RichCompareBool(newitem, parent, Py_LT); if (cmp == -1) { Py_DECREF(newitem); return -1; @@ -74,9 +68,10 @@ _siftup(PyListObject *heap, Py_ssize_t pos) /* Set childpos to index of smaller child. */ rightpos = childpos + 1; if (rightpos < endpos) { - cmp = cmp_lt( + cmp = PyObject_RichCompareBool( PyList_GET_ITEM(heap, childpos), - PyList_GET_ITEM(heap, rightpos)); + PyList_GET_ITEM(heap, rightpos), + Py_LT); if (cmp == -1) { Py_DECREF(newitem); return -1; @@ -219,7 +214,7 @@ heappushpop(PyObject *self, PyObject *args) return item; } - cmp = cmp_lt(PyList_GET_ITEM(heap, 0), item); + cmp = PyObject_RichCompareBool(PyList_GET_ITEM(heap, 0), item, Py_LT); if (cmp == -1) return NULL; if (cmp == 0) { @@ -318,7 +313,7 @@ nlargest(PyObject *self, PyObject *args) else goto sortit; } - cmp = cmp_lt(sol, elem); + cmp = PyObject_RichCompareBool(sol, elem, Py_LT); if (cmp == -1) { Py_DECREF(elem); goto fail; @@ -373,7 +368,7 @@ _siftdownmax(PyListObject *heap, Py_ssize_t startpos, Py_ssize_t pos) while (pos > startpos){ parentpos = (pos - 1) >> 1; parent = PyList_GET_ITEM(heap, parentpos); - cmp = cmp_lt(parent, newitem); + cmp = PyObject_RichCompareBool(parent, newitem, Py_LT); if (cmp == -1) { Py_DECREF(newitem); return -1; @@ -413,9 +408,10 @@ _siftupmax(PyListObject *heap, Py_ssize_t pos) /* Set childpos to index of smaller child. */ rightpos = childpos + 1; if (rightpos < endpos) { - cmp = cmp_lt( + cmp = PyObject_RichCompareBool( PyList_GET_ITEM(heap, rightpos), - PyList_GET_ITEM(heap, childpos)); + PyList_GET_ITEM(heap, childpos), + Py_LT); if (cmp == -1) { Py_DECREF(newitem); return -1; @@ -488,7 +484,7 @@ nsmallest(PyObject *self, PyObject *args) else goto sortit; } - cmp = cmp_lt(elem, los); + cmp = PyObject_RichCompareBool(elem, los, Py_LT); if (cmp == -1) { Py_DECREF(elem); goto fail; |