rust/library/alloc/src/vec
bors dba8e2d2c2 Auto merge of #128234 - jcsp:retain-empty-case, r=tgross35
Optimize empty case in Vec::retain

While profiling some code that happens to call Vec::retain() in a tight loop, I noticed more runtime than expected in retain, even in a bench case where the vector was always empty.  When I wrapped my call to retain in `if !myvec.is_empty()` I saw faster execution compared with doing retain on an empty vector.

On closer inspection, Vec::retain is doing set_len(0) on itself even when the vector is empty, and then resetting the length again in BackshiftOnDrop::drop.

Unscientific screengrab of a flamegraph illustrating how we end up spending time in set_len and drop:
![image](https://github.com/user-attachments/assets/ebc72ace-84a0-4432-9b6f-1b3c96d353ba)
2024-07-30 00:55:52 +00:00
..
cow.rs Reformat use declarations. 2024-07-29 08:26:52 +10:00
drain.rs Reformat use declarations. 2024-07-29 08:26:52 +10:00
extract_if.rs Reformat use declarations. 2024-07-29 08:26:52 +10:00
in_place_collect.rs Reformat use declarations. 2024-07-29 08:26:52 +10:00
in_place_drop.rs Reformat use declarations. 2024-07-29 08:26:52 +10:00
into_iter.rs Reformat use declarations. 2024-07-29 08:26:52 +10:00
is_zero.rs Use generic NonZero everywhere in alloc. 2024-02-22 15:17:34 +01:00
mod.rs Auto merge of #128234 - jcsp:retain-empty-case, r=tgross35 2024-07-30 00:55:52 +00:00
partial_eq.rs Reformat use declarations. 2024-07-29 08:26:52 +10:00
set_len_on_drop.rs Tune RepeatWith::try_fold and Take::for_each and Vec::extend_trusted 2022-11-24 19:14:19 -08:00
spec_extend.rs Reformat use declarations. 2024-07-29 08:26:52 +10:00
spec_from_elem.rs Reformat use declarations. 2024-07-29 08:26:52 +10:00
spec_from_iter.rs Avoid more NonNull-raw-NonNull roundtrips in Vec 2024-04-12 18:14:29 -04:00
spec_from_iter_nested.rs Reformat use declarations. 2024-07-29 08:26:52 +10:00
splice.rs Reformat use declarations. 2024-07-29 08:26:52 +10:00