Coverage Report

Created: 2026-04-12 06:14

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/cpython3/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
400M
{
12
400M
    Py_ssize_t pos;
13
14
400M
    assert(str_len >= 0);
15
400M
    if (sub_len == 0)
16
0
        return offset;
17
18
400M
    pos = FASTSEARCH(str, str_len, sub, sub_len, -1, FAST_SEARCH);
19
20
400M
    if (pos >= 0)
21
5.49k
        pos += offset;
22
23
400M
    return pos;
24
400M
}
unicodeobject.c:asciilib_find
Line
Count
Source
11
4.27k
{
12
4.27k
    Py_ssize_t pos;
13
14
4.27k
    assert(str_len >= 0);
15
4.27k
    if (sub_len == 0)
16
0
        return offset;
17
18
4.27k
    pos = FASTSEARCH(str, str_len, sub, sub_len, -1, FAST_SEARCH);
19
20
4.27k
    if (pos >= 0)
21
4.27k
        pos += offset;
22
23
4.27k
    return pos;
24
4.27k
}
unicodeobject.c:ucs1lib_find
Line
Count
Source
11
399M
{
12
399M
    Py_ssize_t pos;
13
14
399M
    assert(str_len >= 0);
15
399M
    if (sub_len == 0)
16
0
        return offset;
17
18
399M
    pos = FASTSEARCH(str, str_len, sub, sub_len, -1, FAST_SEARCH);
19
20
399M
    if (pos >= 0)
21
66
        pos += offset;
22
23
399M
    return pos;
24
399M
}
unicodeobject.c:ucs2lib_find
Line
Count
Source
11
132
{
12
132
    Py_ssize_t pos;
13
14
132
    assert(str_len >= 0);
15
132
    if (sub_len == 0)
16
0
        return offset;
17
18
132
    pos = FASTSEARCH(str, str_len, sub, sub_len, -1, FAST_SEARCH);
19
20
132
    if (pos >= 0)
21
132
        pos += offset;
22
23
132
    return pos;
24
132
}
unicodeobject.c:ucs4lib_find
Line
Count
Source
11
175
{
12
175
    Py_ssize_t pos;
13
14
175
    assert(str_len >= 0);
15
175
    if (sub_len == 0)
16
0
        return offset;
17
18
175
    pos = FASTSEARCH(str, str_len, sub, sub_len, -1, FAST_SEARCH);
19
20
175
    if (pos >= 0)
21
175
        pos += offset;
22
23
175
    return pos;
24
175
}
bytes_methods.c:stringlib_find
Line
Count
Source
11
2.78k
{
12
2.78k
    Py_ssize_t pos;
13
14
2.78k
    assert(str_len >= 0);
15
2.78k
    if (sub_len == 0)
16
0
        return offset;
17
18
2.78k
    pos = FASTSEARCH(str, str_len, sub, sub_len, -1, FAST_SEARCH);
19
20
2.78k
    if (pos >= 0)
21
843
        pos += offset;
22
23
2.78k
    return pos;
24
2.78k
}
Unexecuted instantiation: bytearrayobject.c:stringlib_find
Unexecuted instantiation: bytesobject.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
0
{
31
0
    Py_ssize_t pos;
32
33
0
    assert(str_len >= 0);
34
0
    if (sub_len == 0)
35
0
        return str_len + offset;
36
37
0
    pos = FASTSEARCH(str, str_len, sub, sub_len, -1, FAST_RSEARCH);
38
39
0
    if (pos >= 0)
40
0
        pos += offset;
41
42
0
    return pos;
43
0
}
Unexecuted instantiation: unicodeobject.c:asciilib_rfind
Unexecuted instantiation: unicodeobject.c:ucs1lib_rfind
Unexecuted instantiation: unicodeobject.c:ucs2lib_rfind
Unexecuted instantiation: unicodeobject.c:ucs4lib_rfind
Unexecuted instantiation: bytes_methods.c:stringlib_rfind
Unexecuted instantiation: bytearrayobject.c:stringlib_rfind
Unexecuted instantiation: bytesobject.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
0
{
50
0
    return STRINGLIB(find)(str + start, end - start, sub, sub_len, start);
51
0
}
Unexecuted instantiation: unicodeobject.c:asciilib_find_slice
Unexecuted instantiation: unicodeobject.c:ucs1lib_find_slice
Unexecuted instantiation: unicodeobject.c:ucs2lib_find_slice
Unexecuted instantiation: unicodeobject.c:ucs4lib_find_slice
Unexecuted instantiation: bytes_methods.c:stringlib_find_slice
Unexecuted instantiation: bytearrayobject.c:stringlib_find_slice
Unexecuted instantiation: bytesobject.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
0
{
58
0
    return STRINGLIB(rfind)(str + start, end - start, sub, sub_len, start);
59
0
}
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
Unexecuted instantiation: bytes_methods.c:stringlib_rfind_slice
Unexecuted instantiation: bytearrayobject.c:stringlib_rfind_slice
Unexecuted instantiation: bytesobject.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 */