summaryrefslogtreecommitdiff
path: root/Objects/bytesobject.c
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@gmail.com>2013-11-04 11:23:05 +0100
committerVictor Stinner <victor.stinner@gmail.com>2013-11-04 11:23:05 +0100
commitfd9e44db371f6e097b8756a004ac3783f7fb2df0 (patch)
treee31413b55c0e03f18c43c360cfccd44b93c74468 /Objects/bytesobject.c
parentc8bc5377ac59c6e6af5c0e925fa0af7d9df7ebc0 (diff)
downloadcpython-git-fd9e44db371f6e097b8756a004ac3783f7fb2df0.tar.gz
Issue #16286: optimize PyUnicode_RichCompare() for identical strings (same
pointer) for any operator, not only Py_EQ and Py_NE. Code of bytes_richcompare() and PyUnicode_RichCompare() is now closer.
Diffstat (limited to 'Objects/bytesobject.c')
-rw-r--r--Objects/bytesobject.c23
1 files changed, 16 insertions, 7 deletions
diff --git a/Objects/bytesobject.c b/Objects/bytesobject.c
index 9aa3ee286b..0a9d04d6db 100644
--- a/Objects/bytesobject.c
+++ b/Objects/bytesobject.c
@@ -842,12 +842,20 @@ bytes_richcompare(PyBytesObject *a, PyBytesObject *b, int op)
}
else if (a == b) {
switch (op) {
- case Py_EQ:case Py_LE:case Py_GE:
+ case Py_EQ:
+ case Py_LE:
+ case Py_GE:
+ /* a string is equal to itself */
result = Py_True;
break;
- case Py_NE:case Py_LT:case Py_GT:
+ case Py_NE:
+ case Py_LT:
+ case Py_GT:
result = Py_False;
break;
+ default:
+ PyErr_BadArgument();
+ return NULL;
}
}
else if (op == Py_EQ || op == Py_NE) {
@@ -856,11 +864,12 @@ bytes_richcompare(PyBytesObject *a, PyBytesObject *b, int op)
result = eq ? Py_True : Py_False;
}
else {
- len_a = Py_SIZE(a); len_b = Py_SIZE(b);
- min_len = (len_a < len_b) ? len_a : len_b;
+ len_a = Py_SIZE(a);
+ len_b = Py_SIZE(b);
+ min_len = Py_MIN(len_a, len_b);
if (min_len > 0) {
c = Py_CHARMASK(*a->ob_sval) - Py_CHARMASK(*b->ob_sval);
- if (c==0)
+ if (c == 0)
c = memcmp(a->ob_sval, b->ob_sval, min_len);
}
else
@@ -873,8 +882,8 @@ bytes_richcompare(PyBytesObject *a, PyBytesObject *b, int op)
case Py_GT: c = c > 0; break;
case Py_GE: c = c >= 0; break;
default:
- assert(op != Py_EQ && op != Py_NE);
- Py_RETURN_NOTIMPLEMENTED;
+ PyErr_BadArgument();
+ return NULL;
}
result = c ? Py_True : Py_False;
}