Line data Source code
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)
7 22993 : unicode_eq(PyObject *aa, PyObject *bb)
8 : {
9 22993 : register PyUnicodeObject *a = (PyUnicodeObject *)aa;
10 22993 : register PyUnicodeObject *b = (PyUnicodeObject *)bb;
11 :
12 22993 : if (PyUnicode_READY(a) == -1 || PyUnicode_READY(b) == -1) {
13 : assert(0 && "unicode_eq ready fail");
14 0 : return 0;
15 : }
16 :
17 22993 : if (PyUnicode_GET_LENGTH(a) != PyUnicode_GET_LENGTH(b))
18 0 : return 0;
19 22993 : if (PyUnicode_GET_LENGTH(a) == 0)
20 0 : return 1;
21 22993 : if (PyUnicode_KIND(a) != PyUnicode_KIND(b))
22 0 : return 0;
23 : /* Just comparing the first byte is enough to see if a and b differ.
24 : * If they are 2 byte or 4 byte character most differences will happen in
25 : * the lower bytes anyways.
26 : */
27 22993 : if (PyUnicode_1BYTE_DATA(a)[0] != PyUnicode_1BYTE_DATA(b)[0])
28 0 : return 0;
29 45986 : if (PyUnicode_KIND(a) == PyUnicode_1BYTE_KIND &&
30 22993 : PyUnicode_GET_LENGTH(a) == 1)
31 0 : return 1;
32 45986 : return memcmp(PyUnicode_1BYTE_DATA(a), PyUnicode_1BYTE_DATA(b),
33 45986 : PyUnicode_GET_LENGTH(a) * PyUnicode_KIND(a)) == 0;
34 : }
|