Coverage Report

Created: 2025-09-04 06:25

/src/cpython/Objects/stringlib/eq.h
Line
Count
Source
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
249M
{
9
249M
    Py_ssize_t len = PyUnicode_GET_LENGTH(str1);
10
249M
    if (PyUnicode_GET_LENGTH(str2) != len) {
11
62.5M
        return 0;
12
62.5M
    }
13
14
186M
    int kind = PyUnicode_KIND(str1);
15
186M
    if (PyUnicode_KIND(str2) != kind) {
16
8.24M
        return 0;
17
8.24M
    }
18
19
178M
    const void *data1 = PyUnicode_DATA(str1);
20
178M
    const void *data2 = PyUnicode_DATA(str2);
21
178M
    return (memcmp(data1, data2, len * kind) == 0);
22
186M
}
dictobject.c:unicode_eq
Line
Count
Source
8
43.2M
{
9
43.2M
    Py_ssize_t len = PyUnicode_GET_LENGTH(str1);
10
43.2M
    if (PyUnicode_GET_LENGTH(str2) != len) {
11
11.0k
        return 0;
12
11.0k
    }
13
14
43.2M
    int kind = PyUnicode_KIND(str1);
15
43.2M
    if (PyUnicode_KIND(str2) != kind) {
16
0
        return 0;
17
0
    }
18
19
43.2M
    const void *data1 = PyUnicode_DATA(str1);
20
43.2M
    const void *data2 = PyUnicode_DATA(str2);
21
43.2M
    return (memcmp(data1, data2, len * kind) == 0);
22
43.2M
}
setobject.c:unicode_eq
Line
Count
Source
8
349k
{
9
349k
    Py_ssize_t len = PyUnicode_GET_LENGTH(str1);
10
349k
    if (PyUnicode_GET_LENGTH(str2) != len) {
11
3
        return 0;
12
3
    }
13
14
349k
    int kind = PyUnicode_KIND(str1);
15
349k
    if (PyUnicode_KIND(str2) != kind) {
16
0
        return 0;
17
0
    }
18
19
349k
    const void *data1 = PyUnicode_DATA(str1);
20
349k
    const void *data2 = PyUnicode_DATA(str2);
21
349k
    return (memcmp(data1, data2, len * kind) == 0);
22
349k
}
unicodeobject.c:unicode_eq
Line
Count
Source
8
205M
{
9
205M
    Py_ssize_t len = PyUnicode_GET_LENGTH(str1);
10
205M
    if (PyUnicode_GET_LENGTH(str2) != len) {
11
62.5M
        return 0;
12
62.5M
    }
13
14
143M
    int kind = PyUnicode_KIND(str1);
15
143M
    if (PyUnicode_KIND(str2) != kind) {
16
8.24M
        return 0;
17
8.24M
    }
18
19
134M
    const void *data1 = PyUnicode_DATA(str1);
20
134M
    const void *data2 = PyUnicode_DATA(str2);
21
134M
    return (memcmp(data1, data2, len * kind) == 0);
22
143M
}