From 619d0bfefd4b35f4acd585724b13de7323021003 Mon Sep 17 00:00:00 2001 From: Matthias Seitz Date: Wed, 21 Feb 2024 19:41:46 +0100 Subject: [PATCH] perf: update added result in place (#6715) --- crates/transaction-pool/src/pool/mod.rs | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/crates/transaction-pool/src/pool/mod.rs b/crates/transaction-pool/src/pool/mod.rs index db45037ef2..4e4aa5664a 100644 --- a/crates/transaction-pool/src/pool/mod.rs +++ b/crates/transaction-pool/src/pool/mod.rs @@ -486,7 +486,7 @@ where origin: TransactionOrigin, transactions: impl IntoIterator>, ) -> Vec> { - let added = + let mut added = transactions.into_iter().map(|tx| self.add_transaction(origin, tx)).collect::>(); // If at least one transaction was added successfully, then we enforce the pool size limits. @@ -504,15 +504,15 @@ where // It may happen that a newly added transaction is immediately discarded, so we need to // adjust the result here - added - .into_iter() - .map(|res| match res { - Ok(ref hash) if discarded.contains(hash) => { - Err(PoolError::new(*hash, PoolErrorKind::DiscardedOnInsert)) + for res in added.iter_mut() { + if let Ok(hash) = res { + if discarded.contains(hash) { + *res = Err(PoolError::new(*hash, PoolErrorKind::DiscardedOnInsert)) } - other => other, - }) - .collect() + } + } + + added } /// Notify all listeners about a new pending transaction.