Issue #3106: Speedup some comparisons. This also removes the last call

to Py_CmpToRich from the codebase (in longobject.c).
This commit is contained in:
Antoine Pitrou 2008-12-20 13:14:23 +00:00
parent c9928ccf01
commit 51f3ef9da0
3 changed files with 90 additions and 73 deletions

View file

@ -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