Coverage Report

Created: 2025-07-04 06:49

/src/cpython/Objects/stringlib/count.h
Line
Count
Source (jump to first uncovered line)
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
72.7M
{
17
72.7M
    Py_ssize_t count;
18
19
72.7M
    if (str_len < 0)
20
0
        return 0; /* start > len(str) */
21
72.7M
    if (sub_len == 0)
22
0
        return (str_len < maxcount) ? str_len + 1 : maxcount;
23
24
72.7M
    count = FASTSEARCH(str, str_len, sub, sub_len, maxcount, FAST_COUNT);
25
26
72.7M
    if (count < 0)
27
0
        return 0; /* no match */
28
29
72.7M
    return count;
30
72.7M
}
Unexecuted instantiation: bytesobject.c:stringlib_count
unicodeobject.c:ucs1lib_count
Line
Count
Source
16
63.7M
{
17
63.7M
    Py_ssize_t count;
18
19
63.7M
    if (str_len < 0)
20
0
        return 0; /* start > len(str) */
21
63.7M
    if (sub_len == 0)
22
0
        return (str_len < maxcount) ? str_len + 1 : maxcount;
23
24
63.7M
    count = FASTSEARCH(str, str_len, sub, sub_len, maxcount, FAST_COUNT);
25
26
63.7M
    if (count < 0)
27
0
        return 0; /* no match */
28
29
63.7M
    return count;
30
63.7M
}
unicodeobject.c:ucs2lib_count
Line
Count
Source
16
7.88M
{
17
7.88M
    Py_ssize_t count;
18
19
7.88M
    if (str_len < 0)
20
0
        return 0; /* start > len(str) */
21
7.88M
    if (sub_len == 0)
22
0
        return (str_len < maxcount) ? str_len + 1 : maxcount;
23
24
7.88M
    count = FASTSEARCH(str, str_len, sub, sub_len, maxcount, FAST_COUNT);
25
26
7.88M
    if (count < 0)
27
0
        return 0; /* no match */
28
29
7.88M
    return count;
30
7.88M
}
unicodeobject.c:ucs4lib_count
Line
Count
Source
16
1.10M
{
17
1.10M
    Py_ssize_t count;
18
19
1.10M
    if (str_len < 0)
20
0
        return 0; /* start > len(str) */
21
1.10M
    if (sub_len == 0)
22
0
        return (str_len < maxcount) ? str_len + 1 : maxcount;
23
24
1.10M
    count = FASTSEARCH(str, str_len, sub, sub_len, maxcount, FAST_COUNT);
25
26
1.10M
    if (count < 0)
27
0
        return 0; /* no match */
28
29
1.10M
    return count;
30
1.10M
}
Unexecuted instantiation: bytes_methods.c:stringlib_count
Unexecuted instantiation: bytearrayobject.c:stringlib_count
31
32
#endif