@@ -8,12 +8,6 @@ annotated by François Pinard, and converted to C by Raymond Hettinger.
8
8
9
9
#include "Python.h"
10
10
11
- static int
12
- cmp_lt (PyObject * x , PyObject * y )
13
- {
14
- return PyObject_RichCompareBool (x , y , Py_LT );
15
- }
16
-
17
11
static int
18
12
_siftdown (PyListObject * heap , Py_ssize_t startpos , Py_ssize_t pos )
19
13
{
@@ -34,7 +28,7 @@ _siftdown(PyListObject *heap, Py_ssize_t startpos, Py_ssize_t pos)
34
28
while (pos > startpos ){
35
29
parentpos = (pos - 1 ) >> 1 ;
36
30
parent = PyList_GET_ITEM (heap , parentpos );
37
- cmp = cmp_lt (newitem , parent );
31
+ cmp = PyObject_RichCompareBool (newitem , parent , Py_LT );
38
32
if (cmp == -1 ) {
39
33
Py_DECREF (newitem );
40
34
return -1 ;
@@ -74,9 +68,10 @@ _siftup(PyListObject *heap, Py_ssize_t pos)
74
68
/* Set childpos to index of smaller child. */
75
69
rightpos = childpos + 1 ;
76
70
if (rightpos < endpos ) {
77
- cmp = cmp_lt (
71
+ cmp = PyObject_RichCompareBool (
78
72
PyList_GET_ITEM (heap , childpos ),
79
- PyList_GET_ITEM (heap , rightpos ));
73
+ PyList_GET_ITEM (heap , rightpos ),
74
+ Py_LT );
80
75
if (cmp == -1 ) {
81
76
Py_DECREF (newitem );
82
77
return -1 ;
@@ -219,7 +214,7 @@ heappushpop(PyObject *self, PyObject *args)
219
214
return item ;
220
215
}
221
216
222
- cmp = cmp_lt (PyList_GET_ITEM (heap , 0 ), item );
217
+ cmp = PyObject_RichCompareBool (PyList_GET_ITEM (heap , 0 ), item , Py_LT );
223
218
if (cmp == -1 )
224
219
return NULL ;
225
220
if (cmp == 0 ) {
@@ -318,7 +313,7 @@ nlargest(PyObject *self, PyObject *args)
318
313
else
319
314
goto sortit ;
320
315
}
321
- cmp = cmp_lt (sol , elem );
316
+ cmp = PyObject_RichCompareBool (sol , elem , Py_LT );
322
317
if (cmp == -1 ) {
323
318
Py_DECREF (elem );
324
319
goto fail ;
@@ -373,7 +368,7 @@ _siftdownmax(PyListObject *heap, Py_ssize_t startpos, Py_ssize_t pos)
373
368
while (pos > startpos ){
374
369
parentpos = (pos - 1 ) >> 1 ;
375
370
parent = PyList_GET_ITEM (heap , parentpos );
376
- cmp = cmp_lt (parent , newitem );
371
+ cmp = PyObject_RichCompareBool (parent , newitem , Py_LT );
377
372
if (cmp == -1 ) {
378
373
Py_DECREF (newitem );
379
374
return -1 ;
@@ -413,9 +408,10 @@ _siftupmax(PyListObject *heap, Py_ssize_t pos)
413
408
/* Set childpos to index of smaller child. */
414
409
rightpos = childpos + 1 ;
415
410
if (rightpos < endpos ) {
416
- cmp = cmp_lt (
411
+ cmp = PyObject_RichCompareBool (
417
412
PyList_GET_ITEM (heap , rightpos ),
418
- PyList_GET_ITEM (heap , childpos ));
413
+ PyList_GET_ITEM (heap , childpos ),
414
+ Py_LT );
419
415
if (cmp == -1 ) {
420
416
Py_DECREF (newitem );
421
417
return -1 ;
@@ -488,7 +484,7 @@ nsmallest(PyObject *self, PyObject *args)
488
484
else
489
485
goto sortit ;
490
486
}
491
- cmp = cmp_lt (elem , los );
487
+ cmp = PyObject_RichCompareBool (elem , los , Py_LT );
492
488
if (cmp == -1 ) {
493
489
Py_DECREF (elem );
494
490
goto fail ;
0 commit comments