Coverage Report

Created: 2025-08-26 06:26

/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
67.3M
        return 0;
12
67.3M
    }
13
14
192M
    int kind = PyUnicode_KIND(str1);
15
192M
    if (PyUnicode_KIND(str2) != kind) {
16
9.89M
        return 0;
17
9.89M
    }
18
19
182M
    const void *data1 = PyUnicode_DATA(str1);
20
182M
    const void *data2 = PyUnicode_DATA(str2);
21
182M
    return (memcmp(data1, data2, len * kind) == 0);
22
192M
}
dictobject.c:unicode_eq
Line
Count
Source
8
39.1M
{
9
39.1M
    Py_ssize_t len = PyUnicode_GET_LENGTH(str1);
10
39.1M
    if (PyUnicode_GET_LENGTH(str2) != len) {
11
12.3k
        return 0;
12
12.3k
    }
13
14
39.1M
    int kind = PyUnicode_KIND(str1);
15
39.1M
    if (PyUnicode_KIND(str2) != kind) {
16
0
        return 0;
17
0
    }
18
19
39.1M
    const void *data1 = PyUnicode_DATA(str1);
20
39.1M
    const void *data2 = PyUnicode_DATA(str2);
21
39.1M
    return (memcmp(data1, data2, len * kind) == 0);
22
39.1M
}
setobject.c:unicode_eq
Line
Count
Source
8
343k
{
9
343k
    Py_ssize_t len = PyUnicode_GET_LENGTH(str1);
10
343k
    if (PyUnicode_GET_LENGTH(str2) != len) {
11
3
        return 0;
12
3
    }
13
14
343k
    int kind = PyUnicode_KIND(str1);
15
343k
    if (PyUnicode_KIND(str2) != kind) {
16
0
        return 0;
17
0
    }
18
19
343k
    const void *data1 = PyUnicode_DATA(str1);
20
343k
    const void *data2 = PyUnicode_DATA(str2);
21
343k
    return (memcmp(data1, data2, len * kind) == 0);
22
343k
}
unicodeobject.c:unicode_eq
Line
Count
Source
8
219M
{
9
219M
    Py_ssize_t len = PyUnicode_GET_LENGTH(str1);
10
219M
    if (PyUnicode_GET_LENGTH(str2) != len) {
11
67.3M
        return 0;
12
67.3M
    }
13
14
152M
    int kind = PyUnicode_KIND(str1);
15
152M
    if (PyUnicode_KIND(str2) != kind) {
16
9.89M
        return 0;
17
9.89M
    }
18
19
142M
    const void *data1 = PyUnicode_DATA(str1);
20
142M
    const void *data2 = PyUnicode_DATA(str2);
21
142M
    return (memcmp(data1, data2, len * kind) == 0);
22
152M
}