Commit a955a777 authored by Stefan Behnel's avatar Stefan Behnel

clean up string comparison optimisation from github #1571

parent 760d0429
...@@ -39,8 +39,8 @@ static int __Pyx_InitStrings(__Pyx_StringTabEntry *t) { ...@@ -39,8 +39,8 @@ static int __Pyx_InitStrings(__Pyx_StringTabEntry *t) {
#endif #endif
if (!*t->p) if (!*t->p)
return -1; return -1;
hash = PyObject_Hash(*t->p); // initialise cached hash value
if (hash == -1) if (PyObject_Hash(*t->p) == -1)
PyErr_Clear(); PyErr_Clear();
++t; ++t;
} }
...@@ -189,20 +189,20 @@ static CYTHON_INLINE int __Pyx_PyUnicode_Equals(PyObject* s1, PyObject* s2, int ...@@ -189,20 +189,20 @@ static CYTHON_INLINE int __Pyx_PyUnicode_Equals(PyObject* s1, PyObject* s2, int
if (length != __Pyx_PyUnicode_GET_LENGTH(s2)) { if (length != __Pyx_PyUnicode_GET_LENGTH(s2)) {
goto return_ne; goto return_ne;
} }
#if CYTHON_COMPILING_IN_CPYTHON #if CYTHON_USE_UNICODE_INTERNALS
#if CYTHON_PEP393_ENABLED
if (((PyASCIIObject*)s1)->hash != ((PyASCIIObject*)s2)->hash
&& ((PyASCIIObject*)s1)->hash != -1 && ((PyASCIIObject*)s2)->hash != -1)
{
goto return_ne;
}
#else
if (((PyUnicodeObject*)s1)->hash != ((PyUnicodeObject*)s2)->hash
&& ((PyUnicodeObject*)s1)->hash != -1 && ((PyUnicodeObject*)s2)->hash != -1)
{ {
goto return_ne; Py_hash_t hash1, hash2;
#if CYTHON_PEP393_ENABLED
hash1 = ((PyASCIIObject*)s1)->hash;
hash2 = ((PyASCIIObject*)s2)->hash;
#else
hash1 = ((PyUnicodeObject*)s1)->hash;
hash2 = ((PyUnicodeObject*)s2)->hash;
#endif
if (hash1 != hash2 && hash1 != -1 && hash2 != -1) {
goto return_ne;
}
} }
#endif
#endif #endif
// len(s1) == len(s2) >= 1 (empty string is interned, and "s1 is not s2") // len(s1) == len(s2) >= 1 (empty string is interned, and "s1 is not s2")
kind = __Pyx_PyUnicode_KIND(s1); kind = __Pyx_PyUnicode_KIND(s1);
...@@ -276,14 +276,16 @@ static CYTHON_INLINE int __Pyx_PyBytes_Equals(PyObject* s1, PyObject* s2, int eq ...@@ -276,14 +276,16 @@ static CYTHON_INLINE int __Pyx_PyBytes_Equals(PyObject* s1, PyObject* s2, int eq
} else if (length == 1) { } else if (length == 1) {
return (equals == Py_EQ); return (equals == Py_EQ);
} else { } else {
#if CYTHON_COMPILING_IN_CPYTHON int result;
if (((PyBytesObject*)s1)->ob_shash != ((PyBytesObject*)s2)->ob_shash #if CYTHON_USE_UNICODE_INTERNALS
&& ((PyBytesObject*)s1)->ob_shash != -1 && ((PyBytesObject*)s2)->ob_shash != -1) Py_hash_t hash1, hash2;
{ hash1 = ((PyBytesObject*)s1)->ob_shash;
hash2 = ((PyBytesObject*)s2)->ob_shash;
if (hash1 != hash2 && hash1 != -1 && hash2 != -1) {
return (equals == Py_NE); return (equals == Py_NE);
} }
#endif #endif
int result = memcmp(ps1, ps2, (size_t)length); result = memcmp(ps1, ps2, (size_t)length);
return (equals == Py_EQ) ? (result == 0) : (result != 0); return (equals == Py_EQ) ? (result == 0) : (result != 0);
} }
} else if ((s1 == Py_None) & PyBytes_CheckExact(s2)) { } else if ((s1 == Py_None) & PyBytes_CheckExact(s2)) {
......
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