perf(AllTransactions-iter): do not clone all transactions by default (#13187)

This commit is contained in:
Hai | RISE
2024-12-07 03:38:20 +07:00
committed by GitHub
parent e615010cc6
commit c608679963
2 changed files with 17 additions and 6 deletions

View File

@ -295,7 +295,7 @@ where
/// Returns _all_ transactions in the pool.
pub fn pooled_transactions(&self) -> Vec<Arc<ValidPoolTransaction<T::Transaction>>> {
self.get_pool_data().all().transactions_iter().filter(|tx| tx.propagate).collect()
self.get_pool_data().all().transactions_iter().filter(|tx| tx.propagate).cloned().collect()
}
/// Returns only the first `max` transactions in the pool.
@ -303,7 +303,13 @@ where
&self,
max: usize,
) -> Vec<Arc<ValidPoolTransaction<T::Transaction>>> {
self.get_pool_data().all().transactions_iter().filter(|tx| tx.propagate).take(max).collect()
self.get_pool_data()
.all()
.transactions_iter()
.filter(|tx| tx.propagate)
.take(max)
.cloned()
.collect()
}
/// Converts the internally tracked transaction to the pooled format.
@ -857,7 +863,12 @@ where
&self,
origin: TransactionOrigin,
) -> Vec<Arc<ValidPoolTransaction<T::Transaction>>> {
self.get_pool_data().all().transactions_iter().filter(|tx| tx.origin == origin).collect()
self.get_pool_data()
.all()
.transactions_iter()
.filter(|tx| tx.origin == origin)
.cloned()
.collect()
}
/// Returns all pending transactions filted by [`TransactionOrigin`]

View File

@ -1095,11 +1095,11 @@ impl<T: PoolTransaction> AllTransactions<T> {
self.by_hash.keys().copied()
}
/// Returns an iterator over all _unique_ hashes in the pool
/// Returns an iterator over all transactions in the pool
pub(crate) fn transactions_iter(
&self,
) -> impl Iterator<Item = Arc<ValidPoolTransaction<T>>> + '_ {
self.by_hash.values().cloned()
) -> impl Iterator<Item = &Arc<ValidPoolTransaction<T>>> + '_ {
self.by_hash.values()
}
/// Returns if the transaction for the given hash is already included in this pool