summaryrefslogtreecommitdiffstats
path: root/Python
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>2001-01-17 15:47:24 (GMT)
committerGuido van Rossum <guido@python.org>2001-01-17 15:47:24 (GMT)
commit53451b3fd19be3b6e7db058c34251898000408df (patch)
treedb2bde324f8768b33e59012d79cf7ffcc849816f /Python
parentac7be6888b7c1ac1ef9dc5294e9e6cb0589b98a3 (diff)
downloadcpython-53451b3fd19be3b6e7db058c34251898000408df.zip
cpython-53451b3fd19be3b6e7db058c34251898000408df.tar.gz
cpython-53451b3fd19be3b6e7db058c34251898000408df.tar.bz2
Use rich comparisons in min and max.
Diffstat (limited to 'Python')
-rw-r--r--Python/bltinmodule.c18
1 files changed, 9 insertions, 9 deletions
diff --git a/Python/bltinmodule.c b/Python/bltinmodule.c
index 8f114f3..683eec0 100644
--- a/Python/bltinmodule.c
+++ b/Python/bltinmodule.c
@@ -1371,7 +1371,7 @@ Return the dictionary containing the current scope's local variables.";
static PyObject *
-min_max(PyObject *args, int sign)
+min_max(PyObject *args, int op)
{
int i;
PyObject *v, *w, *x;
@@ -1401,16 +1401,16 @@ min_max(PyObject *args, int sign)
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 @@ min_max(PyObject *args, int sign)
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 @@ With two or more arguments, return the smallest argument.";
static PyObject *
builtin_max(PyObject *self, PyObject *v)
{
- return min_max(v, 1);
+ return min_max(v, Py_GT);
}
static char max_doc[] =