mirror of
https://gitlab.com/pulsechaincom/lighthouse-pulse.git
synced 2024-12-23 12:07:17 +00:00
Avoid allocations on VariableList (#1921)
## Issue Addressed NA ## Proposed Changes Avoids lots of grow allocations when decoding a `VariableList` of fixed-length items. This is the function used for decoding the `state.validators` list. ## Additional Info NA
This commit is contained in:
parent
398919b5d4
commit
5114aee5cf
@ -247,8 +247,10 @@ where
|
||||
|
||||
bytes
|
||||
.chunks(T::ssz_fixed_len())
|
||||
.map(|chunk| T::from_ssz_bytes(chunk))
|
||||
.collect::<Result<Vec<_>, _>>()
|
||||
.try_fold(Vec::with_capacity(num_items), |mut vec, chunk| {
|
||||
vec.push(T::from_ssz_bytes(chunk)?);
|
||||
Ok(vec)
|
||||
})
|
||||
.map(Into::into)
|
||||
} else {
|
||||
ssz::decode_list_of_variable_length_items(bytes, Some(max_len)).map(|vec| vec.into())
|
||||
|
Loading…
Reference in New Issue
Block a user