Coverage Report

Created: 2026-12-01 06:09

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/cpython/Objects/stringlib/count.h
Line
Count
Source
1
/* stringlib: count implementation */
2
3
#ifndef STRINGLIB_FASTSEARCH_H
4
#error must include "stringlib/fastsearch.h" before including this module
5
#endif
6
7
// gh-97982: Implementing asciilib_count() is not worth it, FASTSEARCH() does
8
// not specialize the code for ASCII strings. Use ucs1lib_count() for ASCII and
9
// UCS1 strings: it's the same than asciilib_count().
10
#if !STRINGLIB_IS_UNICODE || STRINGLIB_MAX_CHAR > 0x7Fu
11
12
Py_LOCAL_INLINE(Py_ssize_t)
13
STRINGLIB(count)(const STRINGLIB_CHAR* str, Py_ssize_t str_len,
14
                const STRINGLIB_CHAR* sub, Py_ssize_t sub_len,
15
                Py_ssize_t maxcount)
16
33.2M
{
17
33.2M
    Py_ssize_t count;
18
19
33.2M
    if (str_len < 0)
20
0
        return 0; /* start > len(str) */
21
33.2M
    if (sub_len == 0)
22
0
        return (str_len < maxcount) ? str_len + 1 : maxcount;
23
24
33.2M
    count = FASTSEARCH(str, str_len, sub, sub_len, maxcount, FAST_COUNT);
25
26
33.2M
    if (count < 0)
27
0
        return 0; /* no match */
28
29
33.2M
    return count;
30
33.2M
}
Unexecuted instantiation: bytesobject.c:stringlib_count
unicodeobject.c:ucs1lib_count
Line
Count
Source
16
26.8M
{
17
26.8M
    Py_ssize_t count;
18
19
26.8M
    if (str_len < 0)
20
0
        return 0; /* start > len(str) */
21
26.8M
    if (sub_len == 0)
22
0
        return (str_len < maxcount) ? str_len + 1 : maxcount;
23
24
26.8M
    count = FASTSEARCH(str, str_len, sub, sub_len, maxcount, FAST_COUNT);
25
26
26.8M
    if (count < 0)
27
0
        return 0; /* no match */
28
29
26.8M
    return count;
30
26.8M
}
unicodeobject.c:ucs2lib_count
Line
Count
Source
16
914k
{
17
914k
    Py_ssize_t count;
18
19
914k
    if (str_len < 0)
20
0
        return 0; /* start > len(str) */
21
914k
    if (sub_len == 0)
22
0
        return (str_len < maxcount) ? str_len + 1 : maxcount;
23
24
914k
    count = FASTSEARCH(str, str_len, sub, sub_len, maxcount, FAST_COUNT);
25
26
914k
    if (count < 0)
27
0
        return 0; /* no match */
28
29
914k
    return count;
30
914k
}
unicodeobject.c:ucs4lib_count
Line
Count
Source
16
140k
{
17
140k
    Py_ssize_t count;
18
19
140k
    if (str_len < 0)
20
0
        return 0; /* start > len(str) */
21
140k
    if (sub_len == 0)
22
0
        return (str_len < maxcount) ? str_len + 1 : maxcount;
23
24
140k
    count = FASTSEARCH(str, str_len, sub, sub_len, maxcount, FAST_COUNT);
25
26
140k
    if (count < 0)
27
0
        return 0; /* no match */
28
29
140k
    return count;
30
140k
}
bytes_methods.c:stringlib_count
Line
Count
Source
16
5.34M
{
17
5.34M
    Py_ssize_t count;
18
19
5.34M
    if (str_len < 0)
20
0
        return 0; /* start > len(str) */
21
5.34M
    if (sub_len == 0)
22
0
        return (str_len < maxcount) ? str_len + 1 : maxcount;
23
24
5.34M
    count = FASTSEARCH(str, str_len, sub, sub_len, maxcount, FAST_COUNT);
25
26
5.34M
    if (count < 0)
27
0
        return 0; /* no match */
28
29
5.34M
    return count;
30
5.34M
}
Unexecuted instantiation: bytearrayobject.c:stringlib_count
31
32
#endif