about summary refs log tree commit diff
path: root/compiler/rustc_llvm/llvm-wrapper/ArchiveWrapper.cpp
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2023-08-09 14:48:55 +0000
committerbors <bors@rust-lang.org>2023-08-09 14:48:55 +0000
commitadd2722677412c40cb4ef41ac46ede4792442f4d (patch)
tree2bd4f63ef0b4969d53feee107c0428c33fc481d9 /compiler/rustc_llvm/llvm-wrapper/ArchiveWrapper.cpp
parent7c595b4599d546dc5f36bc4bebbbf8ad454fed62 (diff)
parentdd25cc349be3dae9b7c7f1ad0465ab14fab773e3 (diff)
downloadrust-add2722677412c40cb4ef41ac46ede4792442f4d.tar.gz
rust-add2722677412c40cb4ef41ac46ede4792442f4d.zip
Auto merge of #11310 - y21:slow_vector_initialization_doc, r=xFrednet,djc
[`slow_vector_initialization`]: clarify why `Vec::new()` + resize is worse

#11198 extended this lint to also warn on `Vec::new()` + `resize(0, len)`, but did not update the lint documentation, so it left some confused (https://github.com/rust-lang/rust-clippy/issues/10938#issuecomment-1663880083).
This PR should make it a bit more clear. (cc `@djc` `@vi` what do you think about this?)

<details>
<summary>More details</summary>

Godbolt for `Vec::new()` + `.resize(x, 0)`: https://godbolt.org/z/e7q9xc9rG

The resize call first does a normal allocation (`__rust_alloc`):
```asm
alloc::raw_vec::finish_grow:
  ...
  cmp     qword ptr [rcx + 8], 0
  je      .LBB1_7  ; if capacity == 0 -> LBB1_7

.LBB1_7:
  ...
  call    qword ptr [rip + __rust_alloc@GOTPCREL]
```

*Then* a memset for zero initialization:
```asm
example::f:
  ...
  xor     esi, esi  ; 0
  call    qword ptr [rip + memset@GOTPCREL]
```
------------

Godbolt for `vec![0; len]`: https://godbolt.org/z/M3vr53vWY

Important bit:
```asm
example::f:
  ...
  call    qword ptr [rip + __rust_alloc_zeroed@GOTPCREL]
```

</details>

changelog: [`slow_vector_initialization`]: clarify why `Vec::new()` + resize is worse than `vec![0; len]`
Diffstat (limited to 'compiler/rustc_llvm/llvm-wrapper/ArchiveWrapper.cpp')
0 files changed, 0 insertions, 0 deletions