summaryrefslogtreecommitdiffstats
path: root/Objects/longobject.c
diff options
context:
space:
mode:
authorAntoine Pitrou <solipsis@pitrou.net>2008-12-20 13:14:23 (GMT)
committerAntoine Pitrou <solipsis@pitrou.net>2008-12-20 13:14:23 (GMT)
commit51f3ef9da082435f063d2e78de1dd20fa65cf0de (patch)
tree254a2f82d7c66ac4ee73de9cd31374af99b11c62 /Objects/longobject.c
parentc9928ccf0184fb3db4b05d7eab8cd366882d513f (diff)
downloadcpython-51f3ef9da082435f063d2e78de1dd20fa65cf0de.zip
cpython-51f3ef9da082435f063d2e78de1dd20fa65cf0de.tar.gz
cpython-51f3ef9da082435f063d2e78de1dd20fa65cf0de.tar.bz2
Issue #3106: Speedup some comparisons. This also removes the last call
to Py_CmpToRich from the codebase (in longobject.c).
Diffstat (limited to 'Objects/longobject.c')
-rw-r--r--Objects/longobject.c39
1 files changed, 35 insertions, 4 deletions
diff --git a/Objects/longobject.c b/Objects/longobject.c
index 677221a..362d0ad 100644
--- a/Objects/longobject.c
+++ b/Objects/longobject.c
@@ -2232,14 +2232,45 @@ long_compare(PyLongObject *a, PyLongObject *b)
return sign < 0 ? -1 : sign > 0 ? 1 : 0;
}
+#define TEST_COND(cond) \
+ ((cond) ? Py_True : Py_False)
+
static PyObject *
long_richcompare(PyObject *self, PyObject *other, int op)
{
- PyObject *result;
+ int result;
+ PyObject *v;
CHECK_BINOP(self, other);
- result = Py_CmpToRich(op, long_compare((PyLongObject*)self,
- (PyLongObject*)other));
- return result;
+ if (self == other)
+ result = 0;
+ else
+ result = long_compare((PyLongObject*)self, (PyLongObject*)other);
+ /* Convert the return value to a Boolean */
+ switch (op) {
+ case Py_EQ:
+ v = TEST_COND(result == 0);
+ break;
+ case Py_NE:
+ v = TEST_COND(result != 0);
+ break;
+ case Py_LE:
+ v = TEST_COND(result <= 0);
+ break;
+ case Py_GE:
+ v = TEST_COND(result >= 0);
+ break;
+ case Py_LT:
+ v = TEST_COND(result == -1);
+ break;
+ case Py_GT:
+ v = TEST_COND(result == 1);
+ break;
+ default:
+ PyErr_BadArgument();
+ return NULL;
+ }
+ Py_INCREF(v);
+ return v;
}
static long