rust/library/alloc
bors f99f9e48ed Auto merge of #98755 - nnethercote:faster-vec-insert, r=cuviper
Optimize `Vec::insert` for the case where `index == len`.

By skipping the call to `copy` with a zero length. This makes it closer
to `push`.

I did this recently for `SmallVec`
(https://github.com/servo/rust-smallvec/pull/282) and it was a big perf win in
one case. Although I don't have a specific use case in mind, it seems
worth doing it for `Vec` as well.

Things to note:
- In the `index < len` case, the number of conditions checked is
  unchanged.
- In the `index == len` case, the number of conditions checked increases
  by one, but the more expensive zero-length copy is avoided.
- In the `index > len` case the code now reserves space for the extra
  element before panicking. This seems like an unimportant change.

r? `@cuviper`
2022-07-03 09:36:37 +00:00
..
benches Add VecDeque::extend TrustedLen benchmark 2022-06-17 23:41:03 +02:00
src Auto merge of #98755 - nnethercote:faster-vec-insert, r=cuviper 2022-07-03 09:36:37 +00:00
tests Rollup merge of #98585 - cuviper:covariant-thinbox, r=thomcc 2022-07-01 20:19:17 +05:30
Cargo.toml