Skip to content

Commit 7772b8f

Browse files
committed
Optimize empty case in Vec::retain
1 parent 355efac commit 7772b8f

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

library/alloc/src/vec/mod.rs

+5
Original file line numberDiff line numberDiff line change
@@ -1711,6 +1711,11 @@ impl<T, A: Allocator> Vec<T, A> {
17111711
F: FnMut(&mut T) -> bool,
17121712
{
17131713
let original_len = self.len();
1714+
1715+
if original_len == 0 {
1716+
return;
1717+
}
1718+
17141719
// Avoid double drop if the drop guard is not executed,
17151720
// since we may make some holes during the process.
17161721
unsafe { self.set_len(0) };

0 commit comments

Comments
 (0)