MCPcopy Index your code
hub / github.com/RustPython/RustPython / count_chars

Function count_chars

crates/wtf8/src/core_str_count.rs:10–20  ·  view source on GitHub ↗
(s: &Wtf8)

Source from the content-addressed store, hash-verified

8
9#[inline]
10pub(super) fn count_chars(s: &Wtf8) -> usize {
11 if s.len() < USIZE_SIZE * UNROLL_INNER {
12 // Avoid entering the optimized implementation for strings where the
13 // difference is not likely to matter, or where it might even be slower.
14 // That said, a ton of thought was not spent on the particular threshold
15 // here, beyond "this value seems to make sense".
16 char_count_general_case(s.as_bytes())
17 } else {
18 do_count_chars(s)
19 }
20}
21
22fn do_count_chars(s: &Wtf8) -> usize {
23 // For correctness, `CHUNK_SIZE` must be:

Callers 1

countMethod · 0.85

Calls 4

char_count_general_caseFunction · 0.85
do_count_charsFunction · 0.85
lenMethod · 0.45
as_bytesMethod · 0.45

Tested by

no test coverage detected