Coverage Report

Created: 2026-10-31 06:21

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/cpython/Objects/stringlib/find.h
Line
Count
Source
1
/* stringlib: find/index implementation */
2
3
#ifndef STRINGLIB_FASTSEARCH_H
4
#error must include "stringlib/fastsearch.h" before including this module
5
#endif
6
7
Py_LOCAL_INLINE(Py_ssize_t)
8
STRINGLIB(find)(const STRINGLIB_CHAR* str, Py_ssize_t str_len,
9
               const STRINGLIB_CHAR* sub, Py_ssize_t sub_len,
10
               Py_ssize_t offset)
11
39.2M
{
12
39.2M
    Py_ssize_t pos;
13
14
39.2M
    assert(str_len >= 0);
15
39.2M
    if (sub_len == 0)
16
0
        return offset;
17
18
39.2M
    pos = FASTSEARCH(str, str_len, sub, sub_len, -1, FAST_SEARCH);
19
20
39.2M
    if (pos >= 0)
21
25.9M
        pos += offset;
22
23
39.2M
    return pos;
24
39.2M
}
Unexecuted instantiation: bytesobject.c:stringlib_find
unicodeobject.c:asciilib_find
Line
Count
Source
11
5.22M
{
12
5.22M
    Py_ssize_t pos;
13
14
5.22M
    assert(str_len >= 0);
15
5.22M
    if (sub_len == 0)
16
0
        return offset;
17
18
5.22M
    pos = FASTSEARCH(str, str_len, sub, sub_len, -1, FAST_SEARCH);
19
20
5.22M
    if (pos >= 0)
21
5.22M
        pos += offset;
22
23
5.22M
    return pos;
24
5.22M
}
unicodeobject.c:ucs1lib_find
Line
Count
Source
11
18.5M
{
12
18.5M
    Py_ssize_t pos;
13
14
18.5M
    assert(str_len >= 0);
15
18.5M
    if (sub_len == 0)
16
0
        return offset;
17
18
18.5M
    pos = FASTSEARCH(str, str_len, sub, sub_len, -1, FAST_SEARCH);
19
20
18.5M
    if (pos >= 0)
21
5.25M
        pos += offset;
22
23
18.5M
    return pos;
24
18.5M
}
unicodeobject.c:ucs2lib_find
Line
Count
Source
11
6.58M
{
12
6.58M
    Py_ssize_t pos;
13
14
6.58M
    assert(str_len >= 0);
15
6.58M
    if (sub_len == 0)
16
0
        return offset;
17
18
6.58M
    pos = FASTSEARCH(str, str_len, sub, sub_len, -1, FAST_SEARCH);
19
20
6.58M
    if (pos >= 0)
21
6.57M
        pos += offset;
22
23
6.58M
    return pos;
24
6.58M
}
unicodeobject.c:ucs4lib_find
Line
Count
Source
11
8.87M
{
12
8.87M
    Py_ssize_t pos;
13
14
8.87M
    assert(str_len >= 0);
15
8.87M
    if (sub_len == 0)
16
0
        return offset;
17
18
8.87M
    pos = FASTSEARCH(str, str_len, sub, sub_len, -1, FAST_SEARCH);
19
20
8.87M
    if (pos >= 0)
21
8.87M
        pos += offset;
22
23
8.87M
    return pos;
24
8.87M
}
bytes_methods.c:stringlib_find
Line
Count
Source
11
2.76k
{
12
2.76k
    Py_ssize_t pos;
13
14
2.76k
    assert(str_len >= 0);
15
2.76k
    if (sub_len == 0)
16
0
        return offset;
17
18
2.76k
    pos = FASTSEARCH(str, str_len, sub, sub_len, -1, FAST_SEARCH);
19
20
2.76k
    if (pos >= 0)
21
2.50k
        pos += offset;
22
23
2.76k
    return pos;
24
2.76k
}
Unexecuted instantiation: bytearrayobject.c:stringlib_find
25
26
Py_LOCAL_INLINE(Py_ssize_t)
27
STRINGLIB(rfind)(const STRINGLIB_CHAR* str, Py_ssize_t str_len,
28
                const STRINGLIB_CHAR* sub, Py_ssize_t sub_len,
29
                Py_ssize_t offset)
30
7.05k
{
31
7.05k
    Py_ssize_t pos;
32
33
7.05k
    assert(str_len >= 0);
34
7.05k
    if (sub_len == 0)
35
0
        return str_len + offset;
36
37
7.05k
    pos = FASTSEARCH(str, str_len, sub, sub_len, -1, FAST_RSEARCH);
38
39
7.05k
    if (pos >= 0)
40
6.96k
        pos += offset;
41
42
7.05k
    return pos;
43
7.05k
}
Unexecuted instantiation: bytesobject.c:stringlib_rfind
Unexecuted instantiation: unicodeobject.c:asciilib_rfind
Unexecuted instantiation: unicodeobject.c:ucs1lib_rfind
Unexecuted instantiation: unicodeobject.c:ucs2lib_rfind
Unexecuted instantiation: unicodeobject.c:ucs4lib_rfind
bytes_methods.c:stringlib_rfind
Line
Count
Source
30
7.05k
{
31
7.05k
    Py_ssize_t pos;
32
33
7.05k
    assert(str_len >= 0);
34
7.05k
    if (sub_len == 0)
35
0
        return str_len + offset;
36
37
7.05k
    pos = FASTSEARCH(str, str_len, sub, sub_len, -1, FAST_RSEARCH);
38
39
7.05k
    if (pos >= 0)
40
6.96k
        pos += offset;
41
42
7.05k
    return pos;
43
7.05k
}
Unexecuted instantiation: bytearrayobject.c:stringlib_rfind
44
45
Py_LOCAL_INLINE(Py_ssize_t)
46
STRINGLIB(find_slice)(const STRINGLIB_CHAR* str, Py_ssize_t str_len,
47
                     const STRINGLIB_CHAR* sub, Py_ssize_t sub_len,
48
                     Py_ssize_t start, Py_ssize_t end)
49
9.02k
{
50
9.02k
    return STRINGLIB(find)(str + start, end - start, sub, sub_len, start);
51
9.02k
}
Unexecuted instantiation: bytesobject.c:stringlib_find_slice
unicodeobject.c:asciilib_find_slice
Line
Count
Source
49
484
{
50
484
    return STRINGLIB(find)(str + start, end - start, sub, sub_len, start);
51
484
}
unicodeobject.c:ucs1lib_find_slice
Line
Count
Source
49
4.27k
{
50
4.27k
    return STRINGLIB(find)(str + start, end - start, sub, sub_len, start);
51
4.27k
}
unicodeobject.c:ucs2lib_find_slice
Line
Count
Source
49
3.39k
{
50
3.39k
    return STRINGLIB(find)(str + start, end - start, sub, sub_len, start);
51
3.39k
}
unicodeobject.c:ucs4lib_find_slice
Line
Count
Source
49
869
{
50
869
    return STRINGLIB(find)(str + start, end - start, sub, sub_len, start);
51
869
}
Unexecuted instantiation: bytes_methods.c:stringlib_find_slice
Unexecuted instantiation: bytearrayobject.c:stringlib_find_slice
52
53
Py_LOCAL_INLINE(Py_ssize_t)
54
STRINGLIB(rfind_slice)(const STRINGLIB_CHAR* str, Py_ssize_t str_len,
55
                      const STRINGLIB_CHAR* sub, Py_ssize_t sub_len,
56
                      Py_ssize_t start, Py_ssize_t end)
57
7.05k
{
58
7.05k
    return STRINGLIB(rfind)(str + start, end - start, sub, sub_len, start);
59
7.05k
}
Unexecuted instantiation: bytesobject.c:stringlib_rfind_slice
Unexecuted instantiation: unicodeobject.c:asciilib_rfind_slice
Unexecuted instantiation: unicodeobject.c:ucs1lib_rfind_slice
Unexecuted instantiation: unicodeobject.c:ucs2lib_rfind_slice
Unexecuted instantiation: unicodeobject.c:ucs4lib_rfind_slice
bytes_methods.c:stringlib_rfind_slice
Line
Count
Source
57
7.05k
{
58
7.05k
    return STRINGLIB(rfind)(str + start, end - start, sub, sub_len, start);
59
7.05k
}
Unexecuted instantiation: bytearrayobject.c:stringlib_rfind_slice
60
61
#ifdef STRINGLIB_WANT_CONTAINS_OBJ
62
63
Py_LOCAL_INLINE(int)
64
STRINGLIB(contains_obj)(PyObject* str, PyObject* sub)
65
{
66
    return STRINGLIB(find)(
67
        STRINGLIB_STR(str), STRINGLIB_LEN(str),
68
        STRINGLIB_STR(sub), STRINGLIB_LEN(sub), 0
69
        ) != -1;
70
}
71
72
#endif /* STRINGLIB_WANT_CONTAINS_OBJ */