Auto merge of #128234 - jcsp:retain-empty-case, r=tgross35 · model-checking/verify-rust-std@f70ce7f (original) (raw)

Original file line number Diff line number Diff line change
@@ -1710,6 +1710,12 @@ impl<T, A: Allocator> Vec<T, A> {
1710 1710 F: FnMut(&mut T) -> bool,
1711 1711 {
1712 1712 let original_len = self.len();
1713 +
1714 +if original_len == 0 {
1715 +// Empty case: explicit return allows better optimization, vs letting compiler infer it
1716 +return;
1717 +}
1718 +
1713 1719 // Avoid double drop if the drop guard is not executed,
1714 1720 // since we may make some holes during the process.
1715 1721 unsafe { self.set_len(0) };