diff -r 494f736f5945 Objects/bytesobject.c --- a/Objects/bytesobject.c Mon Nov 04 11:28:26 2013 +0100 +++ b/Objects/bytesobject.c Mon Nov 04 11:29:49 2013 +0100 @@ -808,6 +808,12 @@ bytes_compare_eq(PyBytesObject *a, PyByt int cmp; Py_ssize_t len; + /* if the hash values are different, the operands are different */ + if (a->ob_shash != b->ob_shash + && a->ob_shash != -1 + && b->ob_shash != -1) + return 0; + len = Py_SIZE(a); if (Py_SIZE(b) != len) return 0; diff -r 494f736f5945 Objects/unicodeobject.c --- a/Objects/unicodeobject.c Mon Nov 04 11:28:26 2013 +0100 +++ b/Objects/unicodeobject.c Mon Nov 04 11:29:49 2013 +0100 @@ -10530,6 +10530,12 @@ unicode_compare_eq(PyObject *str1, PyObj Py_ssize_t len; int cmp; + /* if the hash values are different, the operands are different */ + if (_PyUnicode_HASH(str1) != _PyUnicode_HASH(str2) + && _PyUnicode_HASH(str1) != -1 + && _PyUnicode_HASH(str2) != -1) + return 0; + len = PyUnicode_GET_LENGTH(str1); if (PyUnicode_GET_LENGTH(str2) != len) return 0;