mirror of https://github.com/rust-lang/rust.git
Optimize empty case in Vec::retain
This commit is contained in:
parent
355efacf0d
commit
6a6824a0ab
|
@ -1711,6 +1711,12 @@ impl<T, A: Allocator> Vec<T, A> {
|
||||||
F: FnMut(&mut T) -> bool,
|
F: FnMut(&mut T) -> bool,
|
||||||
{
|
{
|
||||||
let original_len = self.len();
|
let original_len = self.len();
|
||||||
|
|
||||||
|
if original_len == 0 {
|
||||||
|
// Empty case: explicit return allows better optimization, vs letting compiler infer it
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Avoid double drop if the drop guard is not executed,
|
// Avoid double drop if the drop guard is not executed,
|
||||||
// since we may make some holes during the process.
|
// since we may make some holes during the process.
|
||||||
unsafe { self.set_len(0) };
|
unsafe { self.set_len(0) };
|
||||||
|
|
Loading…
Reference in New Issue