mirror of
https://github.com/sigp/lighthouse.git
synced 2026-04-16 12:28:24 +00:00
Add optimized SSZ decoding for fixed-len items (#865)
* Add custom SSZ decode for Validator * Move efficient decode into macro * Don't allocate SSZ offset to heap * Use smallvec in SszDecoder * Fix test compile error
This commit is contained in:
@@ -1,4 +1,7 @@
|
||||
use super::*;
|
||||
use smallvec::{smallvec, SmallVec};
|
||||
|
||||
type SmallVec8<T> = SmallVec<[T; 8]>;
|
||||
|
||||
pub mod impls;
|
||||
|
||||
@@ -62,8 +65,8 @@ pub struct Offset {
|
||||
/// See [`SszDecoder`](struct.SszDecoder.html) for usage examples.
|
||||
pub struct SszDecoderBuilder<'a> {
|
||||
bytes: &'a [u8],
|
||||
items: Vec<&'a [u8]>,
|
||||
offsets: Vec<Offset>,
|
||||
items: SmallVec8<&'a [u8]>,
|
||||
offsets: SmallVec8<Offset>,
|
||||
items_index: usize,
|
||||
}
|
||||
|
||||
@@ -73,8 +76,8 @@ impl<'a> SszDecoderBuilder<'a> {
|
||||
pub fn new(bytes: &'a [u8]) -> Self {
|
||||
Self {
|
||||
bytes,
|
||||
items: vec![],
|
||||
offsets: vec![],
|
||||
items: smallvec![],
|
||||
offsets: smallvec![],
|
||||
items_index: 0,
|
||||
}
|
||||
}
|
||||
@@ -204,7 +207,7 @@ impl<'a> SszDecoderBuilder<'a> {
|
||||
///
|
||||
/// ```
|
||||
pub struct SszDecoder<'a> {
|
||||
items: Vec<&'a [u8]>,
|
||||
items: SmallVec8<&'a [u8]>,
|
||||
}
|
||||
|
||||
impl<'a> SszDecoder<'a> {
|
||||
|
||||
Reference in New Issue
Block a user