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