Coverage Report

Created: 2026-02-26 06:53

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
170M
{
12
170M
    Py_ssize_t pos;
13
14
170M
    assert(str_len >= 0);
15
170M
    if (sub_len == 0)
16
0
        return offset;
17
18
170M
    pos = FASTSEARCH(str, str_len, sub, sub_len, -1, FAST_SEARCH);
19
20
170M
    if (pos >= 0)
21
152M
        pos += offset;
22
23
170M
    return pos;
24
170M
}
Unexecuted instantiation: bytesobject.c:stringlib_find
unicodeobject.c:asciilib_find
Line
Count
Source
11
27.3M
{
12
27.3M
    Py_ssize_t pos;
13
14
27.3M
    assert(str_len >= 0);
15
27.3M
    if (sub_len == 0)
16
0
        return offset;
17
18
27.3M
    pos = FASTSEARCH(str, str_len, sub, sub_len, -1, FAST_SEARCH);
19
20
27.3M
    if (pos >= 0)
21
27.3M
        pos += offset;
22
23
27.3M
    return pos;
24
27.3M
}
unicodeobject.c:ucs1lib_find
Line
Count
Source
11
21.7M
{
12
21.7M
    Py_ssize_t pos;
13
14
21.7M
    assert(str_len >= 0);
15
21.7M
    if (sub_len == 0)
16
0
        return offset;
17
18
21.7M
    pos = FASTSEARCH(str, str_len, sub, sub_len, -1, FAST_SEARCH);
19
20
21.7M
    if (pos >= 0)
21
4.19M
        pos += offset;
22
23
21.7M
    return pos;
24
21.7M
}
unicodeobject.c:ucs2lib_find
Line
Count
Source
11
69.5M
{
12
69.5M
    Py_ssize_t pos;
13
14
69.5M
    assert(str_len >= 0);
15
69.5M
    if (sub_len == 0)
16
0
        return offset;
17
18
69.5M
    pos = FASTSEARCH(str, str_len, sub, sub_len, -1, FAST_SEARCH);
19
20
69.5M
    if (pos >= 0)
21
69.5M
        pos += offset;
22
23
69.5M
    return pos;
24
69.5M
}
unicodeobject.c:ucs4lib_find
Line
Count
Source
11
51.3M
{
12
51.3M
    Py_ssize_t pos;
13
14
51.3M
    assert(str_len >= 0);
15
51.3M
    if (sub_len == 0)
16
0
        return offset;
17
18
51.3M
    pos = FASTSEARCH(str, str_len, sub, sub_len, -1, FAST_SEARCH);
19
20
51.3M
    if (pos >= 0)
21
51.3M
        pos += offset;
22
23
51.3M
    return pos;
24
51.3M
}
bytes_methods.c:stringlib_find
Line
Count
Source
11
2.52k
{
12
2.52k
    Py_ssize_t pos;
13
14
2.52k
    assert(str_len >= 0);
15
2.52k
    if (sub_len == 0)
16
0
        return offset;
17
18
2.52k
    pos = FASTSEARCH(str, str_len, sub, sub_len, -1, FAST_SEARCH);
19
20
2.52k
    if (pos >= 0)
21
2.33k
        pos += offset;
22
23
2.52k
    return pos;
24
2.52k
}
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.13k
        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.13k
        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
584k
{
50
584k
    return STRINGLIB(find)(str + start, end - start, sub, sub_len, start);
51
584k
}
Unexecuted instantiation: bytesobject.c:stringlib_find_slice
unicodeobject.c:asciilib_find_slice
Line
Count
Source
49
226k
{
50
226k
    return STRINGLIB(find)(str + start, end - start, sub, sub_len, start);
51
226k
}
unicodeobject.c:ucs1lib_find_slice
Line
Count
Source
49
131k
{
50
131k
    return STRINGLIB(find)(str + start, end - start, sub, sub_len, start);
51
131k
}
unicodeobject.c:ucs2lib_find_slice
Line
Count
Source
49
105k
{
50
105k
    return STRINGLIB(find)(str + start, end - start, sub, sub_len, start);
51
105k
}
unicodeobject.c:ucs4lib_find_slice
Line
Count
Source
49
120k
{
50
120k
    return STRINGLIB(find)(str + start, end - start, sub, sub_len, start);
51
120k
}
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 */