summaryrefslogtreecommitdiffstats
path: root/src/tools/clippy/src/docs/naive_bytecount.txt
blob: 24659dc79ae71882a097e6b5be3131b12ef30eaf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
### What it does
Checks for naive byte counts

### Why is this bad?
The [`bytecount`](https://crates.io/crates/bytecount)
crate has methods to count your bytes faster, especially for large slices.

### Known problems
If you have predominantly small slices, the
`bytecount::count(..)` method may actually be slower. However, if you can
ensure that less than 2³²-1 matches arise, the `naive_count_32(..)` can be
faster in those cases.

### Example
```
let count = vec.iter().filter(|x| **x == 0u8).count();
```

Use instead:
```
let count = bytecount::count(&vec, 0u8);
```