Coverage Report

Created: 2025-07-11 06:24

/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
224M
{
9
224M
    Py_ssize_t len = PyUnicode_GET_LENGTH(str1);
10
224M
    if (PyUnicode_GET_LENGTH(str2) != len) {
11
57.4M
        return 0;
12
57.4M
    }
13
14
166M
    int kind = PyUnicode_KIND(str1);
15
166M
    if (PyUnicode_KIND(str2) != kind) {
16
7.54M
        return 0;
17
7.54M
    }
18
19
159M
    const void *data1 = PyUnicode_DATA(str1);
20
159M
    const void *data2 = PyUnicode_DATA(str2);
21
159M
    return (memcmp(data1, data2, len * kind) == 0);
22
166M
}
dictobject.c:unicode_eq
Line
Count
Source
8
30.8M
{
9
30.8M
    Py_ssize_t len = PyUnicode_GET_LENGTH(str1);
10
30.8M
    if (PyUnicode_GET_LENGTH(str2) != len) {
11
7.53k
        return 0;
12
7.53k
    }
13
14
30.8M
    int kind = PyUnicode_KIND(str1);
15
30.8M
    if (PyUnicode_KIND(str2) != kind) {
16
0
        return 0;
17
0
    }
18
19
30.8M
    const void *data1 = PyUnicode_DATA(str1);
20
30.8M
    const void *data2 = PyUnicode_DATA(str2);
21
30.8M
    return (memcmp(data1, data2, len * kind) == 0);
22
30.8M
}
setobject.c:unicode_eq
Line
Count
Source
8
261k
{
9
261k
    Py_ssize_t len = PyUnicode_GET_LENGTH(str1);
10
261k
    if (PyUnicode_GET_LENGTH(str2) != len) {
11
3
        return 0;
12
3
    }
13
14
261k
    int kind = PyUnicode_KIND(str1);
15
261k
    if (PyUnicode_KIND(str2) != kind) {
16
0
        return 0;
17
0
    }
18
19
261k
    const void *data1 = PyUnicode_DATA(str1);
20
261k
    const void *data2 = PyUnicode_DATA(str2);
21
261k
    return (memcmp(data1, data2, len * kind) == 0);
22
261k
}
unicodeobject.c:unicode_eq
Line
Count
Source
8
192M
{
9
192M
    Py_ssize_t len = PyUnicode_GET_LENGTH(str1);
10
192M
    if (PyUnicode_GET_LENGTH(str2) != len) {
11
57.4M
        return 0;
12
57.4M
    }
13
14
135M
    int kind = PyUnicode_KIND(str1);
15
135M
    if (PyUnicode_KIND(str2) != kind) {
16
7.54M
        return 0;
17
7.54M
    }
18
19
127M
    const void *data1 = PyUnicode_DATA(str1);
20
127M
    const void *data2 = PyUnicode_DATA(str2);
21
127M
    return (memcmp(data1, data2, len * kind) == 0);
22
135M
}