SIGN IN SIGN UP
rust-lang / rust UNCLAIMED

Empowering everyone to build reliable and efficient software.

0 0 65 Rust

Auto merge of #148486 - kpreid:vec-iter-drop, r=jhpratt

Explicitly forget the zero remaining elements in `vec::IntoIter::fold()`.



[Original description:] ~~This seems to help LLVM notice that dropping the elements in the destructor of `IntoIter` is not necessary. In cases it doesn’t help, it should be cheap since it is just one assignment.~~

This PR adds a function to `vec::IntoIter()` which is used used by `fold()` and `spec_extend()`, when those operations complete, to forget the zero remaining elements and only deallocate the allocation, ensuring that there will never be a useless loop to drop zero remaining elements when the iterator is dropped.

This is my first ever attempt at this kind of codegen micro-optimization in the standard library, so please let me know what should go into the PR or what sort of additional systematic testing might indicate this is a good or bad idea.
B
bors committed
30d0309fa821f7a0984a9629e0d227ca3c0d2eda