Commits

Anonymous committed 3c36849

Inline cmp_lt().

Comments (0)

Files changed (1)

Modules/_heapqmodule.c

 #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;
     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;
         /* 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;
         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) {
             else
                 goto sortit;
         }
-        cmp = cmp_lt(sol, elem);
+        cmp = PyObject_RichCompareBool(sol, elem, Py_LT);
         if (cmp == -1) {
             Py_DECREF(elem);
             goto fail;
     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;
         /* 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;
             else
                 goto sortit;
         }
-        cmp = cmp_lt(elem, los);
+        cmp = PyObject_RichCompareBool(elem, los, Py_LT);
         if (cmp == -1) {
             Py_DECREF(elem);
             goto fail;