Commit 7409172f authored by Claudio Freire's avatar Claudio Freire

Relocate hash check to improve worst case

parent 0ec031fa
......@@ -263,13 +263,6 @@ static CYTHON_INLINE int __Pyx_PyBytes_Equals(PyObject* s1, PyObject* s2, int eq
Py_ssize_t length = PyBytes_GET_SIZE(s1);
if (length != PyBytes_GET_SIZE(s2))
return (equals == Py_NE);
#if CYTHON_COMPILING_IN_CPYTHON
if (((PyBytesObject*)s1)->ob_shash != ((PyBytesObject*)s2)->ob_shash
&& ((PyBytesObject*)s1)->ob_shash != -1 && ((PyBytesObject*)s2)->ob_shash != -1)
{
return (equals == Py_NE);
}
#endif
// len(s1) == len(s2) >= 1 (empty string is interned, and "s1 is not s2")
ps1 = PyBytes_AS_STRING(s1);
ps2 = PyBytes_AS_STRING(s2);
......@@ -278,6 +271,13 @@ static CYTHON_INLINE int __Pyx_PyBytes_Equals(PyObject* s1, PyObject* s2, int eq
} else if (length == 1) {
return (equals == Py_EQ);
} else {
#if CYTHON_COMPILING_IN_CPYTHON
if (((PyBytesObject*)s1)->ob_shash != ((PyBytesObject*)s2)->ob_shash
&& ((PyBytesObject*)s1)->ob_shash != -1 && ((PyBytesObject*)s2)->ob_shash != -1)
{
return (equals == Py_NE);
}
#endif
int result = memcmp(ps1, ps2, (size_t)length);
return (equals == Py_EQ) ? (result == 0) : (result != 0);
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment