Coverage Report

Created: 2026-04-12 06:54

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
46.0M
{
12
46.0M
    Py_ssize_t pos;
13
14
46.0M
    assert(str_len >= 0);
15
46.0M
    if (sub_len == 0)
16
0
        return offset;
17
18
46.0M
    pos = FASTSEARCH(str, str_len, sub, sub_len, -1, FAST_SEARCH);
19
20
46.0M
    if (pos >= 0)
21
25.2M
        pos += offset;
22
23
46.0M
    return pos;
24
46.0M
}
Unexecuted instantiation: bytesobject.c:stringlib_find
unicodeobject.c:asciilib_find
Line
Count
Source
11
5.06M
{
12
5.06M
    Py_ssize_t pos;
13
14
5.06M
    assert(str_len >= 0);
15
5.06M
    if (sub_len == 0)
16
0
        return offset;
17
18
5.06M
    pos = FASTSEARCH(str, str_len, sub, sub_len, -1, FAST_SEARCH);
19
20
5.06M
    if (pos >= 0)
21
5.05M
        pos += offset;
22
23
5.06M
    return pos;
24
5.06M
}
unicodeobject.c:ucs1lib_find
Line
Count
Source
11
25.4M
{
12
25.4M
    Py_ssize_t pos;
13
14
25.4M
    assert(str_len >= 0);
15
25.4M
    if (sub_len == 0)
16
0
        return offset;
17
18
25.4M
    pos = FASTSEARCH(str, str_len, sub, sub_len, -1, FAST_SEARCH);
19
20
25.4M
    if (pos >= 0)
21
4.70M
        pos += offset;
22
23
25.4M
    return pos;
24
25.4M
}
unicodeobject.c:ucs2lib_find
Line
Count
Source
11
7.23M
{
12
7.23M
    Py_ssize_t pos;
13
14
7.23M
    assert(str_len >= 0);
15
7.23M
    if (sub_len == 0)
16
0
        return offset;
17
18
7.23M
    pos = FASTSEARCH(str, str_len, sub, sub_len, -1, FAST_SEARCH);
19
20
7.23M
    if (pos >= 0)
21
7.21M
        pos += offset;
22
23
7.23M
    return pos;
24
7.23M
}
unicodeobject.c:ucs4lib_find
Line
Count
Source
11
8.25M
{
12
8.25M
    Py_ssize_t pos;
13
14
8.25M
    assert(str_len >= 0);
15
8.25M
    if (sub_len == 0)
16
0
        return offset;
17
18
8.25M
    pos = FASTSEARCH(str, str_len, sub, sub_len, -1, FAST_SEARCH);
19
20
8.25M
    if (pos >= 0)
21
8.24M
        pos += offset;
22
23
8.25M
    return pos;
24
8.25M
}
bytes_methods.c:stringlib_find
Line
Count
Source
11
1.17k
{
12
1.17k
    Py_ssize_t pos;
13
14
1.17k
    assert(str_len >= 0);
15
1.17k
    if (sub_len == 0)
16
0
        return offset;
17
18
1.17k
    pos = FASTSEARCH(str, str_len, sub, sub_len, -1, FAST_SEARCH);
19
20
1.17k
    if (pos >= 0)
21
969
        pos += offset;
22
23
1.17k
    return pos;
24
1.17k
}
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.22k
{
31
7.22k
    Py_ssize_t pos;
32
33
7.22k
    assert(str_len >= 0);
34
7.22k
    if (sub_len == 0)
35
0
        return str_len + offset;
36
37
7.22k
    pos = FASTSEARCH(str, str_len, sub, sub_len, -1, FAST_RSEARCH);
38
39
7.22k
    if (pos >= 0)
40
7.10k
        pos += offset;
41
42
7.22k
    return pos;
43
7.22k
}
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.22k
{
31
7.22k
    Py_ssize_t pos;
32
33
7.22k
    assert(str_len >= 0);
34
7.22k
    if (sub_len == 0)
35
0
        return str_len + offset;
36
37
7.22k
    pos = FASTSEARCH(str, str_len, sub, sub_len, -1, FAST_RSEARCH);
38
39
7.22k
    if (pos >= 0)
40
7.10k
        pos += offset;
41
42
7.22k
    return pos;
43
7.22k
}
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
1.03M
{
50
1.03M
    return STRINGLIB(find)(str + start, end - start, sub, sub_len, start);
51
1.03M
}
Unexecuted instantiation: bytesobject.c:stringlib_find_slice
unicodeobject.c:asciilib_find_slice
Line
Count
Source
49
407k
{
50
407k
    return STRINGLIB(find)(str + start, end - start, sub, sub_len, start);
51
407k
}
unicodeobject.c:ucs1lib_find_slice
Line
Count
Source
49
296k
{
50
296k
    return STRINGLIB(find)(str + start, end - start, sub, sub_len, start);
51
296k
}
unicodeobject.c:ucs2lib_find_slice
Line
Count
Source
49
257k
{
50
257k
    return STRINGLIB(find)(str + start, end - start, sub, sub_len, start);
51
257k
}
unicodeobject.c:ucs4lib_find_slice
Line
Count
Source
49
75.3k
{
50
75.3k
    return STRINGLIB(find)(str + start, end - start, sub, sub_len, start);
51
75.3k
}
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.22k
{
58
7.22k
    return STRINGLIB(rfind)(str + start, end - start, sub, sub_len, start);
59
7.22k
}
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.22k
{
58
7.22k
    return STRINGLIB(rfind)(str + start, end - start, sub, sub_len, start);
59
7.22k
}
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 */