This repository was archived by the owner on May 28, 2025. It is now read-only.
Commit 361898b
committed
Auto merge of rust-lang#116568 - kornelski:hint-reserved, r=<try>
Hint optimizer about reserved capacity
The fact that `Vec` had capacity increased is not known to the optimizer, because functions like `do_reserve_and_handle` are not inlined. (rust-lang#82801) Because of that, code such as:
```rust
vec.try_reserve(123)?;
vec.extend_from_slice(&s[..123]);
```
Tries to reserve the capacity **twice**. This is unnecessary code bloat.
https://rust.godbolt.org/z/YWY16Ezej
Adding a hint after reserve optimizes out the next check of `self.needs_to_grow(len, additional)`.File tree
2 files changed
+6
-1
lines changed- library/alloc/src
- tests/ui/hygiene
2 files changed
+6
-1
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
292 | 292 | | |
293 | 293 | | |
294 | 294 | | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
295 | 300 | | |
296 | 301 | | |
297 | 302 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
| 1 | + | |
2 | 2 | | |
3 | 3 | | |
0 commit comments