• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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)7 unicode_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         Py_UNREACHABLE();
14     }
15 
16     if (PyUnicode_GET_LENGTH(a) != PyUnicode_GET_LENGTH(b))
17         return 0;
18     if (PyUnicode_GET_LENGTH(a) == 0)
19         return 1;
20     if (PyUnicode_KIND(a) != PyUnicode_KIND(b))
21         return 0;
22     return memcmp(PyUnicode_1BYTE_DATA(a), PyUnicode_1BYTE_DATA(b),
23                   PyUnicode_GET_LENGTH(a) * PyUnicode_KIND(a)) == 0;
24 }
25