mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
perf(db): use encode_to in Scale implementations (#11297)
This commit is contained in:
@ -22,7 +22,7 @@ where
|
||||
}
|
||||
|
||||
fn compress_to_buf<B: bytes::BufMut + AsMut<[u8]>>(self, buf: &mut B) {
|
||||
buf.put_slice(&parity_scale_codec::Encode::encode(&self))
|
||||
parity_scale_codec::Encode::encode_to(&self, OutputCompat::wrap_mut(buf));
|
||||
}
|
||||
}
|
||||
|
||||
@ -50,3 +50,22 @@ impl sealed::Sealed for Vec<u8> {}
|
||||
|
||||
impl_compression_for_scale!(U256);
|
||||
impl_compression_for_scale!(u8, u32, u16, u64);
|
||||
|
||||
#[repr(transparent)]
|
||||
struct OutputCompat<B>(B);
|
||||
|
||||
impl<B> OutputCompat<B> {
|
||||
fn wrap_mut(buf: &mut B) -> &mut Self {
|
||||
unsafe { std::mem::transmute(buf) }
|
||||
}
|
||||
}
|
||||
|
||||
impl<B: bytes::BufMut> parity_scale_codec::Output for OutputCompat<B> {
|
||||
fn write(&mut self, bytes: &[u8]) {
|
||||
self.0.put_slice(bytes);
|
||||
}
|
||||
|
||||
fn push_byte(&mut self, byte: u8) {
|
||||
self.0.put_u8(byte);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user