feat: impl InMemorySize for PooledTx (#12791)

This commit is contained in:
Matthias Seitz
2024-11-22 20:41:46 +01:00
committed by GitHub
parent 71fd63d9ac
commit 9a7a733a08
3 changed files with 42 additions and 1 deletions

View File

@ -10,15 +10,32 @@ pub trait InMemorySize {
impl<T: InMemorySize> InMemorySize for alloy_consensus::Signed<T> {
fn size(&self) -> usize {
T::size(self.tx()) + core::mem::size_of::<Signature>() + core::mem::size_of::<TxHash>()
T::size(self.tx()) + self.signature().size() + self.hash().size()
}
}
/// Implement `InMemorySize` for a type with `size_of`
macro_rules! impl_in_mem_size_size_of {
($($ty:ty),*) => {
$(
impl InMemorySize for $ty {
#[inline]
fn size(&self) -> usize {
core::mem::size_of::<Self>()
}
}
)*
};
}
impl_in_mem_size_size_of!(Signature, TxHash);
/// Implement `InMemorySize` for a type with a native `size` method.
macro_rules! impl_in_mem_size {
($($ty:ty),*) => {
$(
impl InMemorySize for $ty {
#[inline]
fn size(&self) -> usize {
Self::size(self)
}