rust/library/alloc/src/vec
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
..
cow.rs Document From impls for cow.rs 2021-05-26 14:21:44 +00:00
drain.rs Rename unsigned_offset_from to sub_ptr 2022-05-11 17:16:25 -07:00
drain_filter.rs style: applying Rust style 2020-12-29 14:03:30 +00:00
in_place_collect.rs Rename unsigned_offset_from to sub_ptr 2022-05-11 17:16:25 -07:00
in_place_drop.rs Rename unsigned_offset_from to sub_ptr 2022-05-11 17:16:25 -07:00
into_iter.rs alloc: fix no_global_oom_handling warnings 2022-06-29 04:44:23 +02:00
is_zero.rs Tweak the calloc optimization to only apply to shortish-arrays 2022-05-01 22:28:11 -07:00
mod.rs Auto merge of #98755 - nnethercote:faster-vec-insert, r=cuviper 2022-07-03 09:36:37 +00:00
partial_eq.rs Allow comparing Vecs with different allocators using == 2022-02-08 01:50:55 +00:00
set_len_on_drop.rs refactor: moved SetLenOnDrop to set_len_on_drop 2020-12-29 14:03:30 +00:00
spec_extend.rs Add VecDeque::extend from vec::IntoIter and slice::Iter specializations 2022-04-28 06:13:54 +02:00
spec_from_elem.rs style: applying Rust style 2020-12-29 14:03:30 +00:00
spec_from_iter.rs Update documentation of SpecFromIter to reflect the removed impls 2021-05-31 21:07:03 +02:00
spec_from_iter_nested.rs Improve estimation of capacity in Vec::from_iter 2022-01-19 09:47:49 -05:00
splice.rs Update expressions where we can use array's IntoIterator implementation 2021-06-02 16:09:04 +06:00