]> git.lizzy.rs Git - rust.git/blob - src/docs/naive_bytecount.txt
24659dc79ae71882a097e6b5be3131b12ef30eaf
[rust.git] / src / docs / naive_bytecount.txt
1 ### What it does
2 Checks for naive byte counts
3
4 ### Why is this bad?
5 The [`bytecount`](https://crates.io/crates/bytecount)
6 crate has methods to count your bytes faster, especially for large slices.
7
8 ### Known problems
9 If you have predominantly small slices, the
10 `bytecount::count(..)` method may actually be slower. However, if you can
11 ensure that less than 2³²-1 matches arise, the `naive_count_32(..)` can be
12 faster in those cases.
13
14 ### Example
15 ```
16 let count = vec.iter().filter(|x| **x == 0u8).count();
17 ```
18
19 Use instead:
20 ```
21 let count = bytecount::count(&vec, 0u8);
22 ```