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:
Paul Hauner
2020-03-04 11:45:01 +11:00
committed by GitHub
parent 58fb144276
commit 871163aecc
6 changed files with 79 additions and 32 deletions

View File

@@ -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> {