Coverage Report

Created: 2026-12-01 06:09

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
52.8M
{
12
52.8M
    Py_ssize_t pos;
13
14
52.8M
    assert(str_len >= 0);
15
52.8M
    if (sub_len == 0)
16
0
        return offset;
17
18
52.8M
    pos = FASTSEARCH(str, str_len, sub, sub_len, -1, FAST_SEARCH);
19
20
52.8M
    if (pos >= 0)
21
26.9M
        pos += offset;
22
23
52.8M
    return pos;
24
52.8M
}
Unexecuted instantiation: bytesobject.c:stringlib_find
unicodeobject.c:asciilib_find
Line
Count
Source
11
4.37M
{
12
4.37M
    Py_ssize_t pos;
13
14
4.37M
    assert(str_len >= 0);
15
4.37M
    if (sub_len == 0)
16
0
        return offset;
17
18
4.37M
    pos = FASTSEARCH(str, str_len, sub, sub_len, -1, FAST_SEARCH);
19
20
4.37M
    if (pos >= 0)
21
4.37M
        pos += offset;
22
23
4.37M
    return pos;
24
4.37M
}
unicodeobject.c:ucs1lib_find
Line
Count
Source
11
31.9M
{
12
31.9M
    Py_ssize_t pos;
13
14
31.9M
    assert(str_len >= 0);
15
31.9M
    if (sub_len == 0)
16
0
        return offset;
17
18
31.9M
    pos = FASTSEARCH(str, str_len, sub, sub_len, -1, FAST_SEARCH);
19
20
31.9M
    if (pos >= 0)
21
5.96M
        pos += offset;
22
23
31.9M
    return pos;
24
31.9M
}
unicodeobject.c:ucs2lib_find
Line
Count
Source
11
7.54M
{
12
7.54M
    Py_ssize_t pos;
13
14
7.54M
    assert(str_len >= 0);
15
7.54M
    if (sub_len == 0)
16
0
        return offset;
17
18
7.54M
    pos = FASTSEARCH(str, str_len, sub, sub_len, -1, FAST_SEARCH);
19
20
7.54M
    if (pos >= 0)
21
7.53M
        pos += offset;
22
23
7.54M
    return pos;
24
7.54M
}
unicodeobject.c:ucs4lib_find
Line
Count
Source
11
9.04M
{
12
9.04M
    Py_ssize_t pos;
13
14
9.04M
    assert(str_len >= 0);
15
9.04M
    if (sub_len == 0)
16
0
        return offset;
17
18
9.04M
    pos = FASTSEARCH(str, str_len, sub, sub_len, -1, FAST_SEARCH);
19
20
9.04M
    if (pos >= 0)
21
9.03M
        pos += offset;
22
23
9.04M
    return pos;
24
9.04M
}
bytes_methods.c:stringlib_find
Line
Count
Source
11
3.17k
{
12
3.17k
    Py_ssize_t pos;
13
14
3.17k
    assert(str_len >= 0);
15
3.17k
    if (sub_len == 0)
16
0
        return offset;
17
18
3.17k
    pos = FASTSEARCH(str, str_len, sub, sub_len, -1, FAST_SEARCH);
19
20
3.17k
    if (pos >= 0)
21
2.89k
        pos += offset;
22
23
3.17k
    return pos;
24
3.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.70k
{
31
7.70k
    Py_ssize_t pos;
32
33
7.70k
    assert(str_len >= 0);
34
7.70k
    if (sub_len == 0)
35
0
        return str_len + offset;
36
37
7.70k
    pos = FASTSEARCH(str, str_len, sub, sub_len, -1, FAST_RSEARCH);
38
39
7.70k
    if (pos >= 0)
40
7.60k
        pos += offset;
41
42
7.70k
    return pos;
43
7.70k
}
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.70k
{
31
7.70k
    Py_ssize_t pos;
32
33
7.70k
    assert(str_len >= 0);
34
7.70k
    if (sub_len == 0)
35
0
        return str_len + offset;
36
37
7.70k
    pos = FASTSEARCH(str, str_len, sub, sub_len, -1, FAST_RSEARCH);
38
39
7.70k
    if (pos >= 0)
40
7.60k
        pos += offset;
41
42
7.70k
    return pos;
43
7.70k
}
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
4.17k
{
50
4.17k
    return STRINGLIB(find)(str + start, end - start, sub, sub_len, start);
51
4.17k
}
Unexecuted instantiation: bytesobject.c:stringlib_find_slice
unicodeobject.c:asciilib_find_slice
Line
Count
Source
49
599
{
50
599
    return STRINGLIB(find)(str + start, end - start, sub, sub_len, start);
51
599
}
unicodeobject.c:ucs1lib_find_slice
Line
Count
Source
49
603
{
50
603
    return STRINGLIB(find)(str + start, end - start, sub, sub_len, start);
51
603
}
unicodeobject.c:ucs2lib_find_slice
Line
Count
Source
49
2.27k
{
50
2.27k
    return STRINGLIB(find)(str + start, end - start, sub, sub_len, start);
51
2.27k
}
unicodeobject.c:ucs4lib_find_slice
Line
Count
Source
49
699
{
50
699
    return STRINGLIB(find)(str + start, end - start, sub, sub_len, start);
51
699
}
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.70k
{
58
7.70k
    return STRINGLIB(rfind)(str + start, end - start, sub, sub_len, start);
59
7.70k
}
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.70k
{
58
7.70k
    return STRINGLIB(rfind)(str + start, end - start, sub, sub_len, start);
59
7.70k
}
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 */