blob: 3e7f5e86c6c9952347e67b180ec0ab0e42151200 [file] [log] [blame]
Christian Heimes0ded5b52007-12-10 15:50:56 +00001/* 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 */
6Py_LOCAL_INLINE(int)
7unicode_eq(PyObject *aa, PyObject *bb)
8{
Antoine Pitrouf95a1b32010-05-09 15:52:27 +00009 register PyUnicodeObject *a = (PyUnicodeObject *)aa;
10 register PyUnicodeObject *b = (PyUnicodeObject *)bb;
Christian Heimes0ded5b52007-12-10 15:50:56 +000011
Antoine Pitrouf95a1b32010-05-09 15:52:27 +000012 if (a->length != b->length)
13 return 0;
14 if (a->length == 0)
15 return 1;
16 if (a->str[0] != b->str[0])
17 return 0;
18 if (a->length == 1)
19 return 1;
20 return memcmp(a->str, b->str, a->length * sizeof(Py_UNICODE)) == 0;
Christian Heimes0ded5b52007-12-10 15:50:56 +000021}