Coverage Report

Created: 2025-07-11 06:24

/src/cpython/Objects/stringlib/find.h
Line
Count
Source (jump to first uncovered line)
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
144M
{
12
144M
    Py_ssize_t pos;
13
14
144M
    assert(str_len >= 0);
15
144M
    if (sub_len == 0)
16
0
        return offset;
17
18
144M
    pos = FASTSEARCH(str, str_len, sub, sub_len, -1, FAST_SEARCH);
19
20
144M
    if (pos >= 0)
21
144M
        pos += offset;
22
23
144M
    return pos;
24
144M
}
Unexecuted instantiation: bytesobject.c:stringlib_find
unicodeobject.c:asciilib_find
Line
Count
Source
11
16.1M
{
12
16.1M
    Py_ssize_t pos;
13
14
16.1M
    assert(str_len >= 0);
15
16.1M
    if (sub_len == 0)
16
0
        return offset;
17
18
16.1M
    pos = FASTSEARCH(str, str_len, sub, sub_len, -1, FAST_SEARCH);
19
20
16.1M
    if (pos >= 0)
21
16.1M
        pos += offset;
22
23
16.1M
    return pos;
24
16.1M
}
unicodeobject.c:ucs1lib_find
Line
Count
Source
11
2.64M
{
12
2.64M
    Py_ssize_t pos;
13
14
2.64M
    assert(str_len >= 0);
15
2.64M
    if (sub_len == 0)
16
0
        return offset;
17
18
2.64M
    pos = FASTSEARCH(str, str_len, sub, sub_len, -1, FAST_SEARCH);
19
20
2.64M
    if (pos >= 0)
21
2.63M
        pos += offset;
22
23
2.64M
    return pos;
24
2.64M
}
unicodeobject.c:ucs2lib_find
Line
Count
Source
11
50.6M
{
12
50.6M
    Py_ssize_t pos;
13
14
50.6M
    assert(str_len >= 0);
15
50.6M
    if (sub_len == 0)
16
0
        return offset;
17
18
50.6M
    pos = FASTSEARCH(str, str_len, sub, sub_len, -1, FAST_SEARCH);
19
20
50.6M
    if (pos >= 0)
21
50.5M
        pos += offset;
22
23
50.6M
    return pos;
24
50.6M
}
unicodeobject.c:ucs4lib_find
Line
Count
Source
11
75.3M
{
12
75.3M
    Py_ssize_t pos;
13
14
75.3M
    assert(str_len >= 0);
15
75.3M
    if (sub_len == 0)
16
0
        return offset;
17
18
75.3M
    pos = FASTSEARCH(str, str_len, sub, sub_len, -1, FAST_SEARCH);
19
20
75.3M
    if (pos >= 0)
21
75.2M
        pos += offset;
22
23
75.3M
    return pos;
24
75.3M
}
bytes_methods.c:stringlib_find
Line
Count
Source
11
2.82k
{
12
2.82k
    Py_ssize_t pos;
13
14
2.82k
    assert(str_len >= 0);
15
2.82k
    if (sub_len == 0)
16
0
        return offset;
17
18
2.82k
    pos = FASTSEARCH(str, str_len, sub, sub_len, -1, FAST_SEARCH);
19
20
2.82k
    if (pos >= 0)
21
2.60k
        pos += offset;
22
23
2.82k
    return pos;
24
2.82k
}
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
4
{
31
4
    Py_ssize_t pos;
32
33
4
    assert(str_len >= 0);
34
4
    if (sub_len == 0)
35
0
        return str_len + offset;
36
37
4
    pos = FASTSEARCH(str, str_len, sub, sub_len, -1, FAST_RSEARCH);
38
39
4
    if (pos >= 0)
40
0
        pos += offset;
41
42
4
    return pos;
43
4
}
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
4
{
31
4
    Py_ssize_t pos;
32
33
4
    assert(str_len >= 0);
34
4
    if (sub_len == 0)
35
0
        return str_len + offset;
36
37
4
    pos = FASTSEARCH(str, str_len, sub, sub_len, -1, FAST_RSEARCH);
38
39
4
    if (pos >= 0)
40
0
        pos += offset;
41
42
4
    return pos;
43
4
}
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
0
{
50
0
    return STRINGLIB(find)(str + start, end - start, sub, sub_len, start);
51
0
}
Unexecuted instantiation: bytesobject.c:stringlib_find_slice
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
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
4
{
58
4
    return STRINGLIB(rfind)(str + start, end - start, sub, sub_len, start);
59
4
}
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
4
{
58
4
    return STRINGLIB(rfind)(str + start, end - start, sub, sub_len, start);
59
4
}
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 */