summaryrefslogtreecommitdiffstats
path: root/src/tools/clippy/src/docs/unnecessary_join.txt
blob: ee4e78601f847ac4d225a795ef9ea74da44dd3d1 (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
25
### What it does
Checks for use of `.collect::<Vec<String>>().join("")` on iterators.

### Why is this bad?
`.collect::<String>()` is more concise and might be more performant

### Example
```
let vector = vec!["hello",  "world"];
let output = vector.iter().map(|item| item.to_uppercase()).collect::<Vec<String>>().join("");
println!("{}", output);
```
The correct use would be:
```
let vector = vec!["hello",  "world"];
let output = vector.iter().map(|item| item.to_uppercase()).collect::<String>();
println!("{}", output);
```
### Known problems
While `.collect::<String>()` is sometimes more performant, there are cases where
using `.collect::<String>()` over `.collect::<Vec<String>>().join("")`
will prevent loop unrolling and will result in a negative performance impact.

Additionally, differences have been observed between aarch64 and x86_64 assembly output,
with aarch64 tending to producing faster assembly in more cases when using `.collect::<String>()`