1 /* Fast unicode equal function optimized for dictobject.c and setobject.c */ 2 3 /* Return 1 if two unicode objects are equal, 0 if not. 4 * unicode_eq() is called when the hash of two unicode objects is equal. 5 */ 6 Py_LOCAL_INLINE(int) unicode_eq(PyObject * aa,PyObject * bb)7unicode_eq(PyObject *aa, PyObject *bb) 8 { 9 PyUnicodeObject *a = (PyUnicodeObject *)aa; 10 PyUnicodeObject *b = (PyUnicodeObject *)bb; 11 12 if (PyUnicode_READY(a) == -1 || PyUnicode_READY(b) == -1) { 13 assert(0 && "unicode_eq ready fail"); 14 return 0; 15 } 16 17 if (PyUnicode_GET_LENGTH(a) != PyUnicode_GET_LENGTH(b)) 18 return 0; 19 if (PyUnicode_GET_LENGTH(a) == 0) 20 return 1; 21 if (PyUnicode_KIND(a) != PyUnicode_KIND(b)) 22 return 0; 23 return memcmp(PyUnicode_1BYTE_DATA(a), PyUnicode_1BYTE_DATA(b), 24 PyUnicode_GET_LENGTH(a) * PyUnicode_KIND(a)) == 0; 25 } 26