Coverage Report

Created: 2025-08-29 06:15

/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
68.6M
{
17
68.6M
    Py_ssize_t count;
18
19
68.6M
    if (str_len < 0)
20
0
        return 0; /* start > len(str) */
21
68.6M
    if (sub_len == 0)
22
0
        return (str_len < maxcount) ? str_len + 1 : maxcount;
23
24
68.6M
    count = FASTSEARCH(str, str_len, sub, sub_len, maxcount, FAST_COUNT);
25
26
68.6M
    if (count < 0)
27
0
        return 0; /* no match */
28
29
68.6M
    return count;
30
68.6M
}
Unexecuted instantiation: bytesobject.c:stringlib_count
unicodeobject.c:ucs1lib_count
Line
Count
Source
16
57.9M
{
17
57.9M
    Py_ssize_t count;
18
19
57.9M
    if (str_len < 0)
20
0
        return 0; /* start > len(str) */
21
57.9M
    if (sub_len == 0)
22
0
        return (str_len < maxcount) ? str_len + 1 : maxcount;
23
24
57.9M
    count = FASTSEARCH(str, str_len, sub, sub_len, maxcount, FAST_COUNT);
25
26
57.9M
    if (count < 0)
27
0
        return 0; /* no match */
28
29
57.9M
    return count;
30
57.9M
}
unicodeobject.c:ucs2lib_count
Line
Count
Source
16
9.88M
{
17
9.88M
    Py_ssize_t count;
18
19
9.88M
    if (str_len < 0)
20
0
        return 0; /* start > len(str) */
21
9.88M
    if (sub_len == 0)
22
0
        return (str_len < maxcount) ? str_len + 1 : maxcount;
23
24
9.88M
    count = FASTSEARCH(str, str_len, sub, sub_len, maxcount, FAST_COUNT);
25
26
9.88M
    if (count < 0)
27
0
        return 0; /* no match */
28
29
9.88M
    return count;
30
9.88M
}
unicodeobject.c:ucs4lib_count
Line
Count
Source
16
798k
{
17
798k
    Py_ssize_t count;
18
19
798k
    if (str_len < 0)
20
0
        return 0; /* start > len(str) */
21
798k
    if (sub_len == 0)
22
0
        return (str_len < maxcount) ? str_len + 1 : maxcount;
23
24
798k
    count = FASTSEARCH(str, str_len, sub, sub_len, maxcount, FAST_COUNT);
25
26
798k
    if (count < 0)
27
0
        return 0; /* no match */
28
29
798k
    return count;
30
798k
}
Unexecuted instantiation: bytes_methods.c:stringlib_count
Unexecuted instantiation: bytearrayobject.c:stringlib_count
31
32
#endif