mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
chore: remove generics from Decode and Decompress (#11295)
This commit is contained in:
@ -87,7 +87,7 @@ where
|
||||
|input| {
|
||||
{
|
||||
for (_, k, _, _) in input {
|
||||
let _ = <T as Table>::Key::decode(k);
|
||||
let _ = <T as Table>::Key::decode(&k);
|
||||
}
|
||||
};
|
||||
black_box(());
|
||||
@ -115,7 +115,7 @@ where
|
||||
|input| {
|
||||
{
|
||||
for (_, _, _, v) in input {
|
||||
let _ = <T as Table>::Value::decompress(v);
|
||||
let _ = <T as Table>::Value::decompress(&v);
|
||||
}
|
||||
};
|
||||
black_box(());
|
||||
|
||||
@ -25,7 +25,7 @@ macro_rules! impl_iai_callgrind_inner {
|
||||
#[library_benchmark]
|
||||
pub fn $decompress() {
|
||||
for (_, _, _, comp) in black_box(load_vectors::<reth_db::tables::$name>()) {
|
||||
let _ = black_box(<reth_db::tables::$name as Table>::Value::decompress(comp));
|
||||
let _ = black_box(<reth_db::tables::$name as Table>::Value::decompress(&comp));
|
||||
}
|
||||
}
|
||||
|
||||
@ -39,7 +39,7 @@ macro_rules! impl_iai_callgrind_inner {
|
||||
#[library_benchmark]
|
||||
pub fn $decode() {
|
||||
for (_, enc, _, _) in black_box(load_vectors::<reth_db::tables::$name>()) {
|
||||
let _ = black_box(<reth_db::tables::$name as Table>::Key::decode(enc));
|
||||
let _ = black_box(<reth_db::tables::$name as Table>::Key::decode(&enc));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -1,7 +1,5 @@
|
||||
#![cfg(feature = "test-utils")]
|
||||
#![allow(missing_docs)]
|
||||
|
||||
use std::{path::Path, sync::Arc};
|
||||
#![cfg(feature = "test-utils")]
|
||||
|
||||
use alloy_primitives::Bytes;
|
||||
use reth_db::{test_utils::create_test_rw_db_with_path, DatabaseEnv};
|
||||
@ -11,6 +9,7 @@ use reth_db_api::{
|
||||
Database,
|
||||
};
|
||||
use reth_fs_util as fs;
|
||||
use std::{path::Path, sync::Arc};
|
||||
|
||||
/// Path where the DB is initialized for benchmarks.
|
||||
#[allow(dead_code)]
|
||||
|
||||
@ -81,7 +81,7 @@ macro_rules! compress_to_buf_or_ref {
|
||||
if let Some(value) = $value.uncompressable_ref() {
|
||||
Some(value)
|
||||
} else {
|
||||
$self.buf.truncate(0);
|
||||
$self.buf.clear();
|
||||
$value.compress_to_buf(&mut $self.buf);
|
||||
None
|
||||
}
|
||||
|
||||
@ -30,13 +30,12 @@ macro_rules! impl_fuzzer_with_input {
|
||||
|
||||
/// Encodes and decodes table types returning its encoded size and the decoded object.
|
||||
/// This method is used for benchmarking, so its parameter should be the actual type that is being tested.
|
||||
pub fn encode_and_decode(obj: $name) -> (usize, $name)
|
||||
{
|
||||
pub fn encode_and_decode(obj: $name) -> (usize, $name) {
|
||||
let data = table::$encode::$encode_method(obj);
|
||||
let size = data.len();
|
||||
|
||||
// Some `data` might be a fixed array.
|
||||
(size, table::$decode::$decode_method(data.to_vec()).expect("failed to decode"))
|
||||
(size, table::$decode::$decode_method(&data).expect("failed to decode"))
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
||||
@ -429,8 +429,8 @@ impl Encode for ChainStateKey {
|
||||
}
|
||||
|
||||
impl Decode for ChainStateKey {
|
||||
fn decode<B: AsRef<[u8]>>(value: B) -> Result<Self, reth_db_api::DatabaseError> {
|
||||
if value.as_ref() == [0] {
|
||||
fn decode(value: &[u8]) -> Result<Self, reth_db_api::DatabaseError> {
|
||||
if value == [0] {
|
||||
Ok(Self::LastFinalizedBlock)
|
||||
} else {
|
||||
Err(reth_db_api::DatabaseError::Decode)
|
||||
|
||||
@ -96,8 +96,12 @@ impl<K: Key> Encode for RawKey<K> {
|
||||
|
||||
// Decode
|
||||
impl<K: Key> Decode for RawKey<K> {
|
||||
fn decode<B: AsRef<[u8]>>(key: B) -> Result<Self, DatabaseError> {
|
||||
Ok(Self { key: key.as_ref().to_vec(), _phantom: std::marker::PhantomData })
|
||||
fn decode(value: &[u8]) -> Result<Self, DatabaseError> {
|
||||
Ok(Self { key: value.to_vec(), _phantom: std::marker::PhantomData })
|
||||
}
|
||||
|
||||
fn decode_owned(value: Vec<u8>) -> Result<Self, DatabaseError> {
|
||||
Ok(Self { key: value, _phantom: std::marker::PhantomData })
|
||||
}
|
||||
}
|
||||
|
||||
@ -168,8 +172,8 @@ impl<V: Value> Compress for RawValue<V> {
|
||||
}
|
||||
|
||||
impl<V: Value> Decompress for RawValue<V> {
|
||||
fn decompress<B: AsRef<[u8]>>(value: B) -> Result<Self, DatabaseError> {
|
||||
Ok(Self { value: value.as_ref().to_vec(), _phantom: std::marker::PhantomData })
|
||||
fn decompress(value: &[u8]) -> Result<Self, DatabaseError> {
|
||||
Ok(Self { value: value.to_vec(), _phantom: std::marker::PhantomData })
|
||||
}
|
||||
|
||||
fn decompress_owned(value: Vec<u8>) -> Result<Self, DatabaseError> {
|
||||
|
||||
@ -6,7 +6,7 @@ use std::borrow::Cow;
|
||||
|
||||
/// Helper function to decode a `(key, value)` pair.
|
||||
pub(crate) fn decoder<'a, T>(
|
||||
kv: (Cow<'a, [u8]>, Cow<'a, [u8]>),
|
||||
(k, v): (Cow<'a, [u8]>, Cow<'a, [u8]>),
|
||||
) -> Result<TableRow<T>, DatabaseError>
|
||||
where
|
||||
T: Table,
|
||||
@ -14,11 +14,11 @@ where
|
||||
T::Value: Decompress,
|
||||
{
|
||||
Ok((
|
||||
match kv.0 {
|
||||
match k {
|
||||
Cow::Borrowed(k) => Decode::decode(k)?,
|
||||
Cow::Owned(k) => Decode::decode(k)?,
|
||||
Cow::Owned(k) => Decode::decode_owned(k)?,
|
||||
},
|
||||
match kv.1 {
|
||||
match v {
|
||||
Cow::Borrowed(v) => Decompress::decompress(v)?,
|
||||
Cow::Owned(v) => Decompress::decompress_owned(v)?,
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user