summaryrefslogtreecommitdiffstats
path: root/src/tools/clippy/src/docs/slow_vector_initialization.txt
blob: 53442e1796541b476163a6750b778535dacbd5c6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
### What it does
Checks slow zero-filled vector initialization

### Why is this bad?
These structures are non-idiomatic and less efficient than simply using
`vec![0; len]`.

### Example
```
let mut vec1 = Vec::with_capacity(len);
vec1.resize(len, 0);

let mut vec1 = Vec::with_capacity(len);
vec1.resize(vec1.capacity(), 0);

let mut vec2 = Vec::with_capacity(len);
vec2.extend(repeat(0).take(len));
```

Use instead:
```
let mut vec1 = vec![0; len];
let mut vec2 = vec![0; len];
```