Debian Codegraph @

Objects/stringlib/eq.h

raw
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 unicode_eq(PyObject *str1, PyObject *str2)
8 {
9 Py_ssize_t len = PyUnicode_GET_LENGTH(str1);
10 if (PyUnicode_GET_LENGTH(str2) != len) {
11 return 0;
12 }
13
14 int kind = PyUnicode_KIND(str1);
15 if (PyUnicode_KIND(str2) != kind) {
16 return 0;
17 }
18
19 const void *data1 = PyUnicode_DATA(str1);
20 const void *data2 = PyUnicode_DATA(str2);
21 return (memcmp(data1, data2, len * kind) == 0);
22 }