rust/library/alloc/tests
bors 1efd804983 Auto merge of #81126 - oxalica:retain-early-drop, r=m-ou-se
Optimize Vec::retain

Use `copy_non_overlapping` instead of `swap` to reduce memory writes, like what we've done in #44355 and `String::retain`.
#48065 already tried to do this optimization but it is reverted in #67300 due to bad codegen of `DrainFilter::drop`.

This PR re-implement the drop-then-move approach. I did a [benchmark](https://gist.github.com/oxalica/3360eec9376f22533fcecff02798b698) on small-no-drop, small-need-drop, large-no-drop elements with different predicate functions. It turns out that the new implementation is >20% faster in average for almost all cases. Only 2/24 cases are slower by 3% and 5%. See the link above for more detail.

I think regression in may-panic cases is due to drop-guard preventing some optimization. If it's permitted to leak elements when predicate function of element's `drop` panic, the new implementation should be almost always faster than current one.
I'm not sure if we should leak on panic, since there is indeed an issue (#52267) complains about it before.
2021-02-11 04:40:57 +00:00
..
arc.rs
binary_heap.rs in-place collect for Vec. Box<[]> and BinaryHeap IntoIter and some adapters 2020-09-03 20:59:03 +02:00
borrow.rs Move various ui const tests to library 2020-09-04 02:35:27 +02:00
boxed.rs review: fix nits and move panic safety tests to the correct place 2020-09-25 23:10:24 +02:00
btree_set_hash.rs Move btree unit test to their native, privileged location 2020-08-14 17:54:09 +02:00
cow_str.rs
fmt.rs review: fix nits and move panic safety tests to the correct place 2020-09-25 23:10:24 +02:00
heap.rs Rename AllocRef to Allocator and (de)alloc to (de)allocate 2020-12-04 14:47:15 +01:00
lib.rs Revert stabilizing integer::BITS. 2021-02-03 22:23:58 +01:00
linked_list.rs
rc.rs
slice.rs Update the slice GroupBy/Mut test 2020-12-10 13:42:31 +01:00
str.rs break formatting so rustfmt is happy 2020-12-02 14:09:36 +01:00
string.rs Fix soundness issue for replace_range and range 2021-01-18 22:14:38 -05:00
vec_deque.rs replace assert! with assert_eq! 2020-12-13 10:21:24 +01:00
vec.rs Auto merge of #81126 - oxalica:retain-early-drop, r=m-ou-se 2021-02-11 04:40:57 +00:00