diff -r b3168643677b Objects/bytesobject.c --- a/Objects/bytesobject.c Tue Apr 09 23:53:26 2013 +0200 +++ b/Objects/bytesobject.c Wed Apr 10 00:11:07 2013 +0200 @@ -834,18 +834,19 @@ bytes_richcompare(PyBytesObject *a, PyBy goto out; } } - if (op == Py_EQ) { - /* Supporting Py_NE here as well does not save - much time, since Py_NE is rarely used. */ - if (Py_SIZE(a) == Py_SIZE(b) - && (a->ob_sval[0] == b->ob_sval[0] - && memcmp(a->ob_sval, b->ob_sval, Py_SIZE(a)) == 0)) { - result = Py_True; - } else { - result = Py_False; - } - goto out; + if (op == Py_EQ || op == Py_NE) { + c = (Py_SIZE(a) == Py_SIZE(b) + && memcmp(a->ob_sval, b->ob_sval, Py_SIZE(a)) == 0); + + if (op == Py_EQ) + result = c ? Py_True : Py_False; + else + result = c ? Py_False : Py_True; + + Py_INCREF(result); + return result; } + len_a = Py_SIZE(a); len_b = Py_SIZE(b); min_len = (len_a < len_b) ? len_a : len_b; if (min_len > 0) { @@ -859,16 +860,14 @@ bytes_richcompare(PyBytesObject *a, PyBy switch (op) { case Py_LT: c = c < 0; break; case Py_LE: c = c <= 0; break; - case Py_EQ: assert(0); break; /* unreachable */ - case Py_NE: c = c != 0; break; case Py_GT: c = c > 0; break; case Py_GE: c = c >= 0; break; default: result = Py_NotImplemented; - goto out; + Py_INCREF(result); + return result; } result = c ? Py_True : Py_False; - out: Py_INCREF(result); return result; } diff -r b3168643677b Objects/stringlib/eq.h --- a/Objects/stringlib/eq.h Tue Apr 09 23:53:26 2013 +0200 +++ b/Objects/stringlib/eq.h Wed Apr 10 00:11:07 2013 +0200 @@ -4,31 +4,28 @@ * unicode_eq() is called when the hash of two unicode objects is equal. */ Py_LOCAL_INLINE(int) -unicode_eq(PyObject *aa, PyObject *bb) +unicode_eq(PyObject *a, PyObject *b) { - register PyUnicodeObject *a = (PyUnicodeObject *)aa; - register PyUnicodeObject *b = (PyUnicodeObject *)bb; + Py_ssize_t len; + void *data1, *data2; if (PyUnicode_READY(a) == -1 || PyUnicode_READY(b) == -1) { assert(0 && "unicode_eq ready fail"); return 0; } - if (PyUnicode_GET_LENGTH(a) != PyUnicode_GET_LENGTH(b)) + /* no "a == b" optimization: the check was already done in the caller */ + + len = PyUnicode_GET_LENGTH(a); + if (PyUnicode_GET_LENGTH(b) != len) return 0; - if (PyUnicode_GET_LENGTH(a) == 0) + if (len == 0) return 1; - if (PyUnicode_KIND(a) != PyUnicode_KIND(b)) + kind = PyUnicode_KIND(a); + if (PyUnicode_KIND(b) != kind) return 0; - /* Just comparing the first byte is enough to see if a and b differ. - * If they are 2 byte or 4 byte character most differences will happen in - * the lower bytes anyways. - */ - if (PyUnicode_1BYTE_DATA(a)[0] != PyUnicode_1BYTE_DATA(b)[0]) - return 0; - if (PyUnicode_KIND(a) == PyUnicode_1BYTE_KIND && - PyUnicode_GET_LENGTH(a) == 1) - return 1; - return memcmp(PyUnicode_1BYTE_DATA(a), PyUnicode_1BYTE_DATA(b), - PyUnicode_GET_LENGTH(a) * PyUnicode_KIND(a)) == 0; + + data1 = PyUnicode_DATA(a); + data2 = PyUnicode_DATA(b); + return (memcmp(data1, data2, len * kind) == 0); }