clippy: Using mem::take is faster as it avoids the allocation: https://rust-lang.github.io/rust-clippy/master/index.html#drain_collect

cargo clippy  --all --all-features --all-targets
warning: you seem to be trying to move all elements into a new `Vec`
   --> src/mmr.rs:501:5
    |
501 |     v.drain(..).collect()
    |     ^^^^^^^^^^^^^^^^^^^^^ help: consider using `mem::take`: `std::mem::take(v)`
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#drain_collect
    = note: `#[warn(clippy::drain_collect)]` on by default

Signed-off-by: Eval EXEC <execvy@gmail.com>
This commit is contained in:
Eval EXEC
2025-03-06 19:38:58 +08:00
parent 6e2e9450a2
commit ee499a9ef0
+2 -1
View File
@@ -16,6 +16,7 @@ use crate::vec::Vec;
use crate::{Error, Merge, Result};
use core::fmt::Debug;
use core::marker::PhantomData;
use core::mem;
#[allow(clippy::upper_case_acronyms)]
pub struct MMR<T, M, S> {
@@ -498,5 +499,5 @@ fn take_while_vec<T, P: Fn(&T) -> bool>(v: &mut Vec<T>, p: P) -> Vec<T> {
return v.drain(..i).collect();
}
}
v.drain(..).collect()
mem::take(v)
}