Skip to content

Commit d7f3084

Browse files
perf(anvil): avoid unnecessary transaction vector cloning in Block::new (#12393)
* Update block.rs * chore: impl encodeable2718 --------- Co-authored-by: Matthias Seitz <[email protected]>
1 parent 1de93fc commit d7f3084

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

crates/anvil/core/src/eth/block.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,7 @@ impl Block {
3232
T: Into<Transaction>,
3333
{
3434
let transactions: Vec<_> = transactions.into_iter().map(Into::into).collect();
35-
let transactions1: Vec<super::transaction::TypedTransaction> =
36-
transactions.clone().into_iter().map(Into::into).collect();
37-
let transactions_root = calculate_transaction_root(&transactions1);
35+
let transactions_root = calculate_transaction_root(&transactions);
3836

3937
Self {
4038
header: Header {

crates/anvil/core/src/eth/transaction/mod.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,12 @@ pub struct MaybeImpersonatedTransaction {
206206
pub impersonated_sender: Option<Address>,
207207
}
208208

209+
impl Typed2718 for MaybeImpersonatedTransaction {
210+
fn ty(&self) -> u8 {
211+
self.transaction.ty()
212+
}
213+
}
214+
209215
impl MaybeImpersonatedTransaction {
210216
/// Creates a new wrapper for the given transaction
211217
pub fn new(transaction: TypedTransaction) -> Self {
@@ -279,6 +285,16 @@ impl MaybeImpersonatedTransaction {
279285
}
280286
}
281287

288+
impl Encodable2718 for MaybeImpersonatedTransaction {
289+
fn encode_2718_len(&self) -> usize {
290+
self.transaction.encode_2718_len()
291+
}
292+
293+
fn encode_2718(&self, out: &mut dyn BufMut) {
294+
self.transaction.encode_2718(out)
295+
}
296+
}
297+
282298
impl Encodable for MaybeImpersonatedTransaction {
283299
fn encode(&self, out: &mut dyn bytes::BufMut) {
284300
self.transaction.encode(out)

0 commit comments

Comments
 (0)