Open LingMan opened 11 months ago
On nightly you can use push_within_capacity to avoid the resizing machinery.
Not really, I need the insert
semantic. The version with push is just an example I came up with while poking at it. And I'm on stable.
Will probably use the arrayvec crate for now.
Looks similar to #114334, but that had pop
followed by push
.
Consider these two examples:
Godbolt: https://rust.godbolt.org/z/PhrMr7dYr
Neither are ever going to grow their Vec from the initial size. Yet,
RawVec::reserve_for_push
and friends are emitted when compiling. Uncommenting theunreachable_unchecked
hints allows the optimizer to clean everything up. Might be asking a lot of the compiler but it would be great if it could figure that out by itself.Tested with Rust 1.74 and with 1.76.0-nightly (87e1447aa 2023-11-30).