Skip to content

Commit 7aec9c0

Browse files
Faster uint decoding (#55)
* Faster uint decoding * Inline encoding as well
1 parent 5b6dd17 commit 7aec9c0

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

ssz/src/decode/impls.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,17 @@ use std::sync::Arc;
1111
macro_rules! impl_decodable_for_uint {
1212
($type: ident, $bit_size: expr) => {
1313
impl Decode for $type {
14+
#[inline(always)]
1415
fn is_ssz_fixed_len() -> bool {
1516
true
1617
}
1718

19+
#[inline(always)]
1820
fn ssz_fixed_len() -> usize {
1921
$bit_size / 8
2022
}
2123

24+
#[inline(always)]
2225
fn from_ssz_bytes(bytes: &[u8]) -> Result<Self, DecodeError> {
2326
let len = bytes.len();
2427
let expected = <Self as Decode>::ssz_fixed_len();

ssz/src/encode/impls.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,22 @@ use std::sync::Arc;
88
macro_rules! impl_encodable_for_uint {
99
($type: ident, $bit_size: expr) => {
1010
impl Encode for $type {
11+
#[inline(always)]
1112
fn is_ssz_fixed_len() -> bool {
1213
true
1314
}
1415

16+
#[inline(always)]
1517
fn ssz_fixed_len() -> usize {
1618
$bit_size / 8
1719
}
1820

21+
#[inline(always)]
1922
fn ssz_bytes_len(&self) -> usize {
2023
$bit_size / 8
2124
}
2225

26+
#[inline(always)]
2327
fn ssz_append(&self, buf: &mut Vec<u8>) {
2428
buf.extend_from_slice(&self.to_le_bytes());
2529
}

0 commit comments

Comments
 (0)