Coverage Report

Created: 2025-08-29 06:15

/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
259M
{
9
259M
    Py_ssize_t len = PyUnicode_GET_LENGTH(str1);
10
259M
    if (PyUnicode_GET_LENGTH(str2) != len) {
11
63.4M
        return 0;
12
63.4M
    }
13
14
196M
    int kind = PyUnicode_KIND(str1);
15
196M
    if (PyUnicode_KIND(str2) != kind) {
16
9.21M
        return 0;
17
9.21M
    }
18
19
186M
    const void *data1 = PyUnicode_DATA(str1);
20
186M
    const void *data2 = PyUnicode_DATA(str2);
21
186M
    return (memcmp(data1, data2, len * kind) == 0);
22
196M
}
dictobject.c:unicode_eq
Line
Count
Source
8
49.4M
{
9
49.4M
    Py_ssize_t len = PyUnicode_GET_LENGTH(str1);
10
49.4M
    if (PyUnicode_GET_LENGTH(str2) != len) {
11
12.6k
        return 0;
12
12.6k
    }
13
14
49.4M
    int kind = PyUnicode_KIND(str1);
15
49.4M
    if (PyUnicode_KIND(str2) != kind) {
16
0
        return 0;
17
0
    }
18
19
49.4M
    const void *data1 = PyUnicode_DATA(str1);
20
49.4M
    const void *data2 = PyUnicode_DATA(str2);
21
49.4M
    return (memcmp(data1, data2, len * kind) == 0);
22
49.4M
}
setobject.c:unicode_eq
Line
Count
Source
8
286k
{
9
286k
    Py_ssize_t len = PyUnicode_GET_LENGTH(str1);
10
286k
    if (PyUnicode_GET_LENGTH(str2) != len) {
11
4
        return 0;
12
4
    }
13
14
286k
    int kind = PyUnicode_KIND(str1);
15
286k
    if (PyUnicode_KIND(str2) != kind) {
16
0
        return 0;
17
0
    }
18
19
286k
    const void *data1 = PyUnicode_DATA(str1);
20
286k
    const void *data2 = PyUnicode_DATA(str2);
21
286k
    return (memcmp(data1, data2, len * kind) == 0);
22
286k
}
unicodeobject.c:unicode_eq
Line
Count
Source
8
209M
{
9
209M
    Py_ssize_t len = PyUnicode_GET_LENGTH(str1);
10
209M
    if (PyUnicode_GET_LENGTH(str2) != len) {
11
63.4M
        return 0;
12
63.4M
    }
13
14
146M
    int kind = PyUnicode_KIND(str1);
15
146M
    if (PyUnicode_KIND(str2) != kind) {
16
9.21M
        return 0;
17
9.21M
    }
18
19
137M
    const void *data1 = PyUnicode_DATA(str1);
20
137M
    const void *data2 = PyUnicode_DATA(str2);
21
137M
    return (memcmp(data1, data2, len * kind) == 0);
22
146M
}