Coverage Report

Created: 2026-02-09 07:07

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
99.2M
{
12
99.2M
    Py_ssize_t pos;
13
14
99.2M
    assert(str_len >= 0);
15
99.2M
    if (sub_len == 0)
16
0
        return offset;
17
18
99.2M
    pos = FASTSEARCH(str, str_len, sub, sub_len, -1, FAST_SEARCH);
19
20
99.2M
    if (pos >= 0)
21
93.2M
        pos += offset;
22
23
99.2M
    return pos;
24
99.2M
}
Unexecuted instantiation: bytesobject.c:stringlib_find
unicodeobject.c:asciilib_find
Line
Count
Source
11
15.8M
{
12
15.8M
    Py_ssize_t pos;
13
14
15.8M
    assert(str_len >= 0);
15
15.8M
    if (sub_len == 0)
16
0
        return offset;
17
18
15.8M
    pos = FASTSEARCH(str, str_len, sub, sub_len, -1, FAST_SEARCH);
19
20
15.8M
    if (pos >= 0)
21
15.8M
        pos += offset;
22
23
15.8M
    return pos;
24
15.8M
}
unicodeobject.c:ucs1lib_find
Line
Count
Source
11
9.84M
{
12
9.84M
    Py_ssize_t pos;
13
14
9.84M
    assert(str_len >= 0);
15
9.84M
    if (sub_len == 0)
16
0
        return offset;
17
18
9.84M
    pos = FASTSEARCH(str, str_len, sub, sub_len, -1, FAST_SEARCH);
19
20
9.84M
    if (pos >= 0)
21
3.91M
        pos += offset;
22
23
9.84M
    return pos;
24
9.84M
}
unicodeobject.c:ucs2lib_find
Line
Count
Source
11
46.6M
{
12
46.6M
    Py_ssize_t pos;
13
14
46.6M
    assert(str_len >= 0);
15
46.6M
    if (sub_len == 0)
16
0
        return offset;
17
18
46.6M
    pos = FASTSEARCH(str, str_len, sub, sub_len, -1, FAST_SEARCH);
19
20
46.6M
    if (pos >= 0)
21
46.6M
        pos += offset;
22
23
46.6M
    return pos;
24
46.6M
}
unicodeobject.c:ucs4lib_find
Line
Count
Source
11
26.8M
{
12
26.8M
    Py_ssize_t pos;
13
14
26.8M
    assert(str_len >= 0);
15
26.8M
    if (sub_len == 0)
16
0
        return offset;
17
18
26.8M
    pos = FASTSEARCH(str, str_len, sub, sub_len, -1, FAST_SEARCH);
19
20
26.8M
    if (pos >= 0)
21
26.8M
        pos += offset;
22
23
26.8M
    return pos;
24
26.8M
}
bytes_methods.c:stringlib_find
Line
Count
Source
11
2.61k
{
12
2.61k
    Py_ssize_t pos;
13
14
2.61k
    assert(str_len >= 0);
15
2.61k
    if (sub_len == 0)
16
0
        return offset;
17
18
2.61k
    pos = FASTSEARCH(str, str_len, sub, sub_len, -1, FAST_SEARCH);
19
20
2.61k
    if (pos >= 0)
21
2.40k
        pos += offset;
22
23
2.61k
    return pos;
24
2.61k
}
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
6.59k
{
31
6.59k
    Py_ssize_t pos;
32
33
6.59k
    assert(str_len >= 0);
34
6.59k
    if (sub_len == 0)
35
0
        return str_len + offset;
36
37
6.59k
    pos = FASTSEARCH(str, str_len, sub, sub_len, -1, FAST_RSEARCH);
38
39
6.59k
    if (pos >= 0)
40
6.50k
        pos += offset;
41
42
6.59k
    return pos;
43
6.59k
}
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
6.59k
{
31
6.59k
    Py_ssize_t pos;
32
33
6.59k
    assert(str_len >= 0);
34
6.59k
    if (sub_len == 0)
35
0
        return str_len + offset;
36
37
6.59k
    pos = FASTSEARCH(str, str_len, sub, sub_len, -1, FAST_RSEARCH);
38
39
6.59k
    if (pos >= 0)
40
6.50k
        pos += offset;
41
42
6.59k
    return pos;
43
6.59k
}
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.05M
{
50
1.05M
    return STRINGLIB(find)(str + start, end - start, sub, sub_len, start);
51
1.05M
}
Unexecuted instantiation: bytesobject.c:stringlib_find_slice
unicodeobject.c:asciilib_find_slice
Line
Count
Source
49
435k
{
50
435k
    return STRINGLIB(find)(str + start, end - start, sub, sub_len, start);
51
435k
}
unicodeobject.c:ucs1lib_find_slice
Line
Count
Source
49
201k
{
50
201k
    return STRINGLIB(find)(str + start, end - start, sub, sub_len, start);
51
201k
}
unicodeobject.c:ucs2lib_find_slice
Line
Count
Source
49
343k
{
50
343k
    return STRINGLIB(find)(str + start, end - start, sub, sub_len, start);
51
343k
}
unicodeobject.c:ucs4lib_find_slice
Line
Count
Source
49
69.7k
{
50
69.7k
    return STRINGLIB(find)(str + start, end - start, sub, sub_len, start);
51
69.7k
}
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
6.59k
{
58
6.59k
    return STRINGLIB(rfind)(str + start, end - start, sub, sub_len, start);
59
6.59k
}
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
6.59k
{
58
6.59k
    return STRINGLIB(rfind)(str + start, end - start, sub, sub_len, start);
59
6.59k
}
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 */