Coverage Report

Created: 2025-07-18 06:09

/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
260M
{
9
260M
    Py_ssize_t len = PyUnicode_GET_LENGTH(str1);
10
260M
    if (PyUnicode_GET_LENGTH(str2) != len) {
11
64.8M
        return 0;
12
64.8M
    }
13
14
195M
    int kind = PyUnicode_KIND(str1);
15
195M
    if (PyUnicode_KIND(str2) != kind) {
16
9.72M
        return 0;
17
9.72M
    }
18
19
185M
    const void *data1 = PyUnicode_DATA(str1);
20
185M
    const void *data2 = PyUnicode_DATA(str2);
21
185M
    return (memcmp(data1, data2, len * kind) == 0);
22
195M
}
dictobject.c:unicode_eq
Line
Count
Source
8
37.2M
{
9
37.2M
    Py_ssize_t len = PyUnicode_GET_LENGTH(str1);
10
37.2M
    if (PyUnicode_GET_LENGTH(str2) != len) {
11
8.78k
        return 0;
12
8.78k
    }
13
14
37.2M
    int kind = PyUnicode_KIND(str1);
15
37.2M
    if (PyUnicode_KIND(str2) != kind) {
16
0
        return 0;
17
0
    }
18
19
37.2M
    const void *data1 = PyUnicode_DATA(str1);
20
37.2M
    const void *data2 = PyUnicode_DATA(str2);
21
37.2M
    return (memcmp(data1, data2, len * kind) == 0);
22
37.2M
}
setobject.c:unicode_eq
Line
Count
Source
8
348k
{
9
348k
    Py_ssize_t len = PyUnicode_GET_LENGTH(str1);
10
348k
    if (PyUnicode_GET_LENGTH(str2) != len) {
11
9
        return 0;
12
9
    }
13
14
348k
    int kind = PyUnicode_KIND(str1);
15
348k
    if (PyUnicode_KIND(str2) != kind) {
16
0
        return 0;
17
0
    }
18
19
348k
    const void *data1 = PyUnicode_DATA(str1);
20
348k
    const void *data2 = PyUnicode_DATA(str2);
21
348k
    return (memcmp(data1, data2, len * kind) == 0);
22
348k
}
unicodeobject.c:unicode_eq
Line
Count
Source
8
222M
{
9
222M
    Py_ssize_t len = PyUnicode_GET_LENGTH(str1);
10
222M
    if (PyUnicode_GET_LENGTH(str2) != len) {
11
64.8M
        return 0;
12
64.8M
    }
13
14
158M
    int kind = PyUnicode_KIND(str1);
15
158M
    if (PyUnicode_KIND(str2) != kind) {
16
9.72M
        return 0;
17
9.72M
    }
18
19
148M
    const void *data1 = PyUnicode_DATA(str1);
20
148M
    const void *data2 = PyUnicode_DATA(str2);
21
148M
    return (memcmp(data1, data2, len * kind) == 0);
22
158M
}