[Python-Dev] Rich Comparison from "C" API?

David Abrahams David Abrahams" <david.abrahams@rcn.com
Wed, 12 Jun 2002 11:48:27 -0400

From: "Tim Peters" <tim.one@comcast.net>

> 1. You really want PyObject_RichCompareBool in your example, not
>    PyObject_RichCompare.  The former is much more efficient in some
>    cases (e.g., a total ordering on dicts is much hairer to determine
>    than just equality).

Now you're really pulling my leg. PyObject_RichCompareBool is just:

/* Return -1 if error; 1 if v op w; 0 if not (v op w). */
PyObject_RichCompareBool(PyObject *v, PyObject *w, int op)
 PyObject *res = PyObject_RichCompare(v, w, op);
 int ok;

 if (res == NULL)
  return -1;
 ok = PyObject_IsTrue(res);
 return ok;

How can that be more efficient that PyObject_RichCompare?