Coverage Report

Created: 2025-09-05 07:10

/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
244M
{
9
244M
    Py_ssize_t len = PyUnicode_GET_LENGTH(str1);
10
244M
    if (PyUnicode_GET_LENGTH(str2) != len) {
11
63.2M
        return 0;
12
63.2M
    }
13
14
181M
    int kind = PyUnicode_KIND(str1);
15
181M
    if (PyUnicode_KIND(str2) != kind) {
16
8.16M
        return 0;
17
8.16M
    }
18
19
173M
    const void *data1 = PyUnicode_DATA(str1);
20
173M
    const void *data2 = PyUnicode_DATA(str2);
21
173M
    return (memcmp(data1, data2, len * kind) == 0);
22
181M
}
dictobject.c:unicode_eq
Line
Count
Source
8
43.4M
{
9
43.4M
    Py_ssize_t len = PyUnicode_GET_LENGTH(str1);
10
43.4M
    if (PyUnicode_GET_LENGTH(str2) != len) {
11
9.93k
        return 0;
12
9.93k
    }
13
14
43.4M
    int kind = PyUnicode_KIND(str1);
15
43.4M
    if (PyUnicode_KIND(str2) != kind) {
16
0
        return 0;
17
0
    }
18
19
43.4M
    const void *data1 = PyUnicode_DATA(str1);
20
43.4M
    const void *data2 = PyUnicode_DATA(str2);
21
43.4M
    return (memcmp(data1, data2, len * kind) == 0);
22
43.4M
}
setobject.c:unicode_eq
Line
Count
Source
8
326k
{
9
326k
    Py_ssize_t len = PyUnicode_GET_LENGTH(str1);
10
326k
    if (PyUnicode_GET_LENGTH(str2) != len) {
11
3
        return 0;
12
3
    }
13
14
326k
    int kind = PyUnicode_KIND(str1);
15
326k
    if (PyUnicode_KIND(str2) != kind) {
16
0
        return 0;
17
0
    }
18
19
326k
    const void *data1 = PyUnicode_DATA(str1);
20
326k
    const void *data2 = PyUnicode_DATA(str2);
21
326k
    return (memcmp(data1, data2, len * kind) == 0);
22
326k
}
unicodeobject.c:unicode_eq
Line
Count
Source
8
201M
{
9
201M
    Py_ssize_t len = PyUnicode_GET_LENGTH(str1);
10
201M
    if (PyUnicode_GET_LENGTH(str2) != len) {
11
63.2M
        return 0;
12
63.2M
    }
13
14
137M
    int kind = PyUnicode_KIND(str1);
15
137M
    if (PyUnicode_KIND(str2) != kind) {
16
8.16M
        return 0;
17
8.16M
    }
18
19
129M
    const void *data1 = PyUnicode_DATA(str1);
20
129M
    const void *data2 = PyUnicode_DATA(str2);
21
129M
    return (memcmp(data1, data2, len * kind) == 0);
22
137M
}