Coverage Report

Created: 2025-07-04 06:49

/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
256M
{
9
256M
    Py_ssize_t len = PyUnicode_GET_LENGTH(str1);
10
256M
    if (PyUnicode_GET_LENGTH(str2) != len) {
11
66.6M
        return 0;
12
66.6M
    }
13
14
190M
    int kind = PyUnicode_KIND(str1);
15
190M
    if (PyUnicode_KIND(str2) != kind) {
16
9.80M
        return 0;
17
9.80M
    }
18
19
180M
    const void *data1 = PyUnicode_DATA(str1);
20
180M
    const void *data2 = PyUnicode_DATA(str2);
21
180M
    return (memcmp(data1, data2, len * kind) == 0);
22
190M
}
dictobject.c:unicode_eq
Line
Count
Source
8
40.5M
{
9
40.5M
    Py_ssize_t len = PyUnicode_GET_LENGTH(str1);
10
40.5M
    if (PyUnicode_GET_LENGTH(str2) != len) {
11
5.42k
        return 0;
12
5.42k
    }
13
14
40.5M
    int kind = PyUnicode_KIND(str1);
15
40.5M
    if (PyUnicode_KIND(str2) != kind) {
16
0
        return 0;
17
0
    }
18
19
40.5M
    const void *data1 = PyUnicode_DATA(str1);
20
40.5M
    const void *data2 = PyUnicode_DATA(str2);
21
40.5M
    return (memcmp(data1, data2, len * kind) == 0);
22
40.5M
}
setobject.c:unicode_eq
Line
Count
Source
8
269k
{
9
269k
    Py_ssize_t len = PyUnicode_GET_LENGTH(str1);
10
269k
    if (PyUnicode_GET_LENGTH(str2) != len) {
11
3
        return 0;
12
3
    }
13
14
269k
    int kind = PyUnicode_KIND(str1);
15
269k
    if (PyUnicode_KIND(str2) != kind) {
16
0
        return 0;
17
0
    }
18
19
269k
    const void *data1 = PyUnicode_DATA(str1);
20
269k
    const void *data2 = PyUnicode_DATA(str2);
21
269k
    return (memcmp(data1, data2, len * kind) == 0);
22
269k
}
unicodeobject.c:unicode_eq
Line
Count
Source
8
216M
{
9
216M
    Py_ssize_t len = PyUnicode_GET_LENGTH(str1);
10
216M
    if (PyUnicode_GET_LENGTH(str2) != len) {
11
66.5M
        return 0;
12
66.5M
    }
13
14
149M
    int kind = PyUnicode_KIND(str1);
15
149M
    if (PyUnicode_KIND(str2) != kind) {
16
9.80M
        return 0;
17
9.80M
    }
18
19
139M
    const void *data1 = PyUnicode_DATA(str1);
20
139M
    const void *data2 = PyUnicode_DATA(str2);
21
139M
    return (memcmp(data1, data2, len * kind) == 0);
22
149M
}