Mercurial > cpython-lru_cache-weakref
diff Python/bltinmodule.c @ 15949:76ad2a9a3e53 legacy-trunk
Use rich comparisons in min and max.
| author | Guido van Rossum <guido@python.org> |
|---|---|
| date | Wed, 17 Jan 2001 15:47:24 +0000 |
| parents | 0ae389e935fc |
| children | 1f92d63b20f0 |
line wrap: on
line diff
--- a/Python/bltinmodule.c Wed Jan 17 15:42:30 2001 +0000 +++ b/Python/bltinmodule.c Wed Jan 17 15:47:24 2001 +0000 @@ -1371,7 +1371,7 @@ static PyObject * -min_max(PyObject *args, int sign) +min_max(PyObject *args, int op) { int i; PyObject *v, *w, *x; @@ -1401,16 +1401,16 @@ if (w == NULL) w = x; else { - int c = PyObject_Compare(x, w); - if (c && PyErr_Occurred()) { + int cmp = PyObject_RichCompareBool(x, w, op); + if (cmp > 0) { + Py_DECREF(w); + w = x; + } + else if (cmp < 0) { Py_DECREF(x); Py_XDECREF(w); return NULL; } - if (c * sign > 0) { - Py_DECREF(w); - w = x; - } else Py_DECREF(x); } @@ -1424,7 +1424,7 @@ static PyObject * builtin_min(PyObject *self, PyObject *v) { - return min_max(v, -1); + return min_max(v, Py_LT); } static char min_doc[] = @@ -1438,7 +1438,7 @@ static PyObject * builtin_max(PyObject *self, PyObject *v) { - return min_max(v, 1); + return min_max(v, Py_GT); } static char max_doc[] =
