chore: simplify size functions (#20560)

This commit is contained in:
DaniPopes
2025-12-22 08:14:50 -03:00
committed by GitHub
parent 807fac0409
commit f3aea8dac0
3 changed files with 4 additions and 15 deletions

View File

@@ -258,10 +258,7 @@ impl<T: TxTy> IsTyped2718 for Receipt<T> {
impl<T: TxTy> InMemorySize for Receipt<T> {
fn size(&self) -> usize {
self.tx_type.size() +
core::mem::size_of::<bool>() +
core::mem::size_of::<u64>() +
self.logs.iter().map(|log| log.size()).sum::<usize>()
size_of::<Self>() + self.logs.iter().map(|log| log.size()).sum::<usize>()
}
}

View File

@@ -472,7 +472,7 @@ impl<B: Block + Default> Default for RecoveredBlock<B> {
impl<B: Block> InMemorySize for RecoveredBlock<B> {
#[inline]
fn size(&self) -> usize {
self.block.size() + self.senders.len() * core::mem::size_of::<Address>()
self.block.size() + self.senders.capacity() * core::mem::size_of::<Address>()
}
}

View File

@@ -6,7 +6,6 @@ use alloy_consensus::{
use alloy_eips::{eip2930::AccessList, eip7702::SignedAuthorization, Typed2718};
use alloy_primitives::{Address, Bytes, ChainId, Signature, TxKind, B256, U256};
use alloy_rlp::{BufMut, Decodable, Encodable};
use core::mem;
use reth_ethereum::primitives::{serde_bincode_compat::RlpBincode, InMemorySize};
/// A transaction with a priority fee ([EIP-1559](https://eips.ethereum.org/EIPS/eip-1559)).
@@ -75,17 +74,10 @@ impl TxPayment {
super::tx::TxTypeCustom::Payment
}
/// Calculates a heuristic for the in-memory size of the [TxPayment]
/// transaction.
/// Calculates a heuristic for the in-memory size of the [TxPayment] transaction.
#[inline]
pub fn size(&self) -> usize {
mem::size_of::<ChainId>() + // chain_id
mem::size_of::<u64>() + // nonce
mem::size_of::<u64>() + // gas_limit
mem::size_of::<u128>() + // max_fee_per_gas
mem::size_of::<u128>() + // max_priority_fee_per_gas
mem::size_of::<Address>() + // to
mem::size_of::<U256>() // value
size_of::<Self>()
}
}