summaryrefslogtreecommitdiffstats
path: root/Objects/listobject.c
diff options
context:
space:
mode:
authorstratakis <cstratak@redhat.com>2017-11-02 10:32:54 (GMT)
committerNick Coghlan <ncoghlan@gmail.com>2017-11-02 10:32:54 (GMT)
commite8b19656396381407ad91473af5da8b0d4346e88 (patch)
tree16638970d5014728a49808d0c80c4af0fe6ccb91 /Objects/listobject.c
parent4f469c096628af730b17798d0ebfd8925bfde836 (diff)
downloadcpython-e8b19656396381407ad91473af5da8b0d4346e88.zip
cpython-e8b19656396381407ad91473af5da8b0d4346e88.tar.gz
cpython-e8b19656396381407ad91473af5da8b0d4346e88.tar.bz2
bpo-23699: Use a macro to reduce boilerplate code in rich comparison functions (GH-793)
Diffstat (limited to 'Objects/listobject.c')
-rw-r--r--Objects/listobject.c27
1 files changed, 3 insertions, 24 deletions
diff --git a/Objects/listobject.c b/Objects/listobject.c
index 8585322..7eba61e 100644
--- a/Objects/listobject.c
+++ b/Objects/listobject.c
@@ -2330,13 +2330,10 @@ list_richcompare(PyObject *v, PyObject *w, int op)
if (Py_SIZE(vl) != Py_SIZE(wl) && (op == Py_EQ || op == Py_NE)) {
/* Shortcut: if the lengths differ, the lists differ */
- PyObject *res;
if (op == Py_EQ)
- res = Py_False;
+ Py_RETURN_FALSE;
else
- res = Py_True;
- Py_INCREF(res);
- return res;
+ Py_RETURN_TRUE;
}
/* Search for the first index where items are different */
@@ -2351,25 +2348,7 @@ list_richcompare(PyObject *v, PyObject *w, int op)
if (i >= Py_SIZE(vl) || i >= Py_SIZE(wl)) {
/* No more items to compare -- compare sizes */
- Py_ssize_t vs = Py_SIZE(vl);
- Py_ssize_t ws = Py_SIZE(wl);
- int cmp;
- PyObject *res;
- switch (op) {
- case Py_LT: cmp = vs < ws; break;
- case Py_LE: cmp = vs <= ws; break;
- case Py_EQ: cmp = vs == ws; break;
- case Py_NE: cmp = vs != ws; break;
- case Py_GT: cmp = vs > ws; break;
- case Py_GE: cmp = vs >= ws; break;
- default: return NULL; /* cannot happen */
- }
- if (cmp)
- res = Py_True;
- else
- res = Py_False;
- Py_INCREF(res);
- return res;
+ Py_RETURN_RICHCOMPARE(Py_SIZE(vl), Py_SIZE(wl), op);
}
/* We have an item that differs -- shortcuts for EQ/NE */