From ee499a9ef0caf3b22478e80380178191bd0a5b07 Mon Sep 17 00:00:00 2001 From: Eval EXEC Date: Thu, 6 Mar 2025 19:38:58 +0800 Subject: [PATCH] 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 --- src/mmr.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/mmr.rs b/src/mmr.rs index fcd32c4..3c298ee 100644 --- a/src/mmr.rs +++ b/src/mmr.rs @@ -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 { @@ -498,5 +499,5 @@ fn take_while_vec bool>(v: &mut Vec, p: P) -> Vec { return v.drain(..i).collect(); } } - v.drain(..).collect() + mem::take(v) }