Mercurial > cpython-lru_cache-weakref
diff Objects/longobject.c @ 50242:ad246cb4f662 3.0
Merged revisions 67871 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/branches/py3k
........
r67871 | antoine.pitrou | 2008-12-20 14:14:23 +0100 (sam., 20 déc. 2008) | 4 lines
Issue #3106: Speedup some comparisons. This also removes the last call
to Py_CmpToRich from the codebase (in longobject.c).
........
| author | Antoine Pitrou <solipsis@pitrou.net> |
|---|---|
| date | Sat, 20 Dec 2008 13:23:02 +0000 |
| parents | de3094bb1421 |
| children | 427e43d0e031 |
line wrap: on
line diff
--- a/Objects/longobject.c Fri Dec 19 23:00:01 2008 +0000 +++ b/Objects/longobject.c Sat Dec 20 13:23:02 2008 +0000 @@ -2232,14 +2232,45 @@ 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
