Skip to content

Commit db6b62e

Browse files
committed
Inline cmp_lt().
1 parent 1784ff0 commit db6b62e

File tree

1 file changed

+11
-15
lines changed

1 file changed

+11
-15
lines changed

Modules/_heapqmodule.c

+11-15
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,6 @@ annotated by François Pinard, and converted to C by Raymond Hettinger.
88

99
#include "Python.h"
1010

11-
static int
12-
cmp_lt(PyObject *x, PyObject *y)
13-
{
14-
return PyObject_RichCompareBool(x, y, Py_LT);
15-
}
16-
1711
static int
1812
_siftdown(PyListObject *heap, Py_ssize_t startpos, Py_ssize_t pos)
1913
{
@@ -34,7 +28,7 @@ _siftdown(PyListObject *heap, Py_ssize_t startpos, Py_ssize_t pos)
3428
while (pos > startpos){
3529
parentpos = (pos - 1) >> 1;
3630
parent = PyList_GET_ITEM(heap, parentpos);
37-
cmp = cmp_lt(newitem, parent);
31+
cmp = PyObject_RichCompareBool(newitem, parent, Py_LT);
3832
if (cmp == -1) {
3933
Py_DECREF(newitem);
4034
return -1;
@@ -74,9 +68,10 @@ _siftup(PyListObject *heap, Py_ssize_t pos)
7468
/* Set childpos to index of smaller child. */
7569
rightpos = childpos + 1;
7670
if (rightpos < endpos) {
77-
cmp = cmp_lt(
71+
cmp = PyObject_RichCompareBool(
7872
PyList_GET_ITEM(heap, childpos),
79-
PyList_GET_ITEM(heap, rightpos));
73+
PyList_GET_ITEM(heap, rightpos),
74+
Py_LT);
8075
if (cmp == -1) {
8176
Py_DECREF(newitem);
8277
return -1;
@@ -219,7 +214,7 @@ heappushpop(PyObject *self, PyObject *args)
219214
return item;
220215
}
221216

222-
cmp = cmp_lt(PyList_GET_ITEM(heap, 0), item);
217+
cmp = PyObject_RichCompareBool(PyList_GET_ITEM(heap, 0), item, Py_LT);
223218
if (cmp == -1)
224219
return NULL;
225220
if (cmp == 0) {
@@ -318,7 +313,7 @@ nlargest(PyObject *self, PyObject *args)
318313
else
319314
goto sortit;
320315
}
321-
cmp = cmp_lt(sol, elem);
316+
cmp = PyObject_RichCompareBool(sol, elem, Py_LT);
322317
if (cmp == -1) {
323318
Py_DECREF(elem);
324319
goto fail;
@@ -373,7 +368,7 @@ _siftdownmax(PyListObject *heap, Py_ssize_t startpos, Py_ssize_t pos)
373368
while (pos > startpos){
374369
parentpos = (pos - 1) >> 1;
375370
parent = PyList_GET_ITEM(heap, parentpos);
376-
cmp = cmp_lt(parent, newitem);
371+
cmp = PyObject_RichCompareBool(parent, newitem, Py_LT);
377372
if (cmp == -1) {
378373
Py_DECREF(newitem);
379374
return -1;
@@ -413,9 +408,10 @@ _siftupmax(PyListObject *heap, Py_ssize_t pos)
413408
/* Set childpos to index of smaller child. */
414409
rightpos = childpos + 1;
415410
if (rightpos < endpos) {
416-
cmp = cmp_lt(
411+
cmp = PyObject_RichCompareBool(
417412
PyList_GET_ITEM(heap, rightpos),
418-
PyList_GET_ITEM(heap, childpos));
413+
PyList_GET_ITEM(heap, childpos),
414+
Py_LT);
419415
if (cmp == -1) {
420416
Py_DECREF(newitem);
421417
return -1;
@@ -488,7 +484,7 @@ nsmallest(PyObject *self, PyObject *args)
488484
else
489485
goto sortit;
490486
}
491-
cmp = cmp_lt(elem, los);
487+
cmp = PyObject_RichCompareBool(elem, los, Py_LT);
492488
if (cmp == -1) {
493489
Py_DECREF(elem);
494490
goto fail;

0 commit comments

Comments
 (0)