rust/library/alloc/src
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
..
alloc Reformat use declarations. 2024-07-29 08:26:52 +10:00
boxed Reformat use declarations. 2024-07-29 08:26:52 +10:00
collections Rollup merge of #128310 - kmicklas:btree-map-peek-next-docs, r=tgross35 2024-07-29 07:11:16 +02:00
ffi Reformat use declarations. 2024-07-29 08:26:52 +10:00
raw_vec Reformat use declarations. 2024-07-29 08:26:52 +10:00
rc Reformat use declarations. 2024-07-29 08:26:52 +10:00
slice Reformat use declarations. 2024-07-29 08:26:52 +10:00
sync Reformat use declarations. 2024-07-29 08:26:52 +10:00
testing Reformat use declarations. 2024-07-29 08:26:52 +10:00
vec Auto merge of #128234 - jcsp:retain-empty-case, r=tgross35 2024-07-30 00:55:52 +00:00
alloc.rs Reformat use declarations. 2024-07-29 08:26:52 +10:00
borrow.rs Reformat use declarations. 2024-07-29 08:26:52 +10:00
boxed.rs Reformat use declarations. 2024-07-29 08:26:52 +10:00
fmt.rs Fix doc nits 2024-07-26 13:26:33 +01:00
lib.miri.rs add 'x.py miri', and make it work for 'library/{core,alloc,std}' 2024-04-03 20:27:20 +02:00
lib.rs Warn on rustdoc::unescaped_backticks for core/alloc/std/test/proc_macro 2024-07-29 00:58:45 +02:00
macros.rs Mark format! with must_use hint 2024-07-06 14:24:20 +02:00
raw_vec.rs Reformat use declarations. 2024-07-29 08:26:52 +10:00
rc.rs Reformat use declarations. 2024-07-29 08:26:52 +10:00
slice.rs Reformat use declarations. 2024-07-29 08:26:52 +10:00
str.rs Reformat use declarations. 2024-07-29 08:26:52 +10:00
string.rs Reformat use declarations. 2024-07-29 08:26:52 +10:00
sync.rs Reformat use declarations. 2024-07-29 08:26:52 +10:00
task.rs Reformat use declarations. 2024-07-29 08:26:52 +10:00
tests.rs Reformat use declarations. 2024-07-29 08:26:52 +10:00