summaryrefslogtreecommitdiffstats
path: root/Objects/bytesobject.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/bytesobject.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/bytesobject.c')
-rw-r--r--Objects/bytesobject.c27
1 files changed, 7 insertions, 20 deletions
diff --git a/Objects/bytesobject.c b/Objects/bytesobject.c
index 7ba90aa..a921d9c 100644
--- a/Objects/bytesobject.c
+++ b/Objects/bytesobject.c
@@ -1566,7 +1566,6 @@ bytes_richcompare(PyBytesObject *a, PyBytesObject *b, int op)
int c;
Py_ssize_t len_a, len_b;
Py_ssize_t min_len;
- PyObject *result;
int rc;
/* Make sure both arguments are strings. */
@@ -1599,7 +1598,7 @@ bytes_richcompare(PyBytesObject *a, PyBytesObject *b, int op)
}
}
}
- result = Py_NotImplemented;
+ Py_RETURN_NOTIMPLEMENTED;
}
else if (a == b) {
switch (op) {
@@ -1607,12 +1606,12 @@ bytes_richcompare(PyBytesObject *a, PyBytesObject *b, int op)
case Py_LE:
case Py_GE:
/* a string is equal to itself */
- result = Py_True;
+ Py_RETURN_TRUE;
break;
case Py_NE:
case Py_LT:
case Py_GT:
- result = Py_False;
+ Py_RETURN_FALSE;
break;
default:
PyErr_BadArgument();
@@ -1622,7 +1621,7 @@ bytes_richcompare(PyBytesObject *a, PyBytesObject *b, int op)
else if (op == Py_EQ || op == Py_NE) {
int eq = bytes_compare_eq(a, b);
eq ^= (op == Py_NE);
- result = eq ? Py_True : Py_False;
+ return PyBool_FromLong(eq);
}
else {
len_a = Py_SIZE(a);
@@ -1635,22 +1634,10 @@ bytes_richcompare(PyBytesObject *a, PyBytesObject *b, int op)
}
else
c = 0;
- if (c == 0)
- c = (len_a < len_b) ? -1 : (len_a > len_b) ? 1 : 0;
- switch (op) {
- case Py_LT: c = c < 0; break;
- case Py_LE: c = c <= 0; break;
- case Py_GT: c = c > 0; break;
- case Py_GE: c = c >= 0; break;
- default:
- PyErr_BadArgument();
- return NULL;
- }
- result = c ? Py_True : Py_False;
+ if (c != 0)
+ Py_RETURN_RICHCOMPARE(c, 0, op);
+ Py_RETURN_RICHCOMPARE(len_a, len_b, op);
}
-
- Py_INCREF(result);
- return result;
}
static Py_hash_t