Skip to content

Commit

Permalink
optimize and simplify decode_size_with_offset()
Browse files Browse the repository at this point in the history
  • Loading branch information
arvidn committed Sep 23, 2024
1 parent 26f446a commit 47bb071
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions src/serde/parse_atom.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,12 @@ pub fn decode_size_with_offset<R: Read>(f: &mut R, initial_b: u8) -> Result<(u8,
return Err(internal_error());
}

let mut atom_start_offset = 0;
let mut bit_mask: u8 = 0x80;
let mut b = initial_b;
while b & bit_mask != 0 {
atom_start_offset += 1;
b &= 0xff ^ bit_mask;
bit_mask >>= 1;
let atom_start_offset = initial_b.leading_ones() as usize;
if atom_start_offset >= 8 {
return Err(bad_encoding());
}
let bit_mask: u8 = 0xff >> atom_start_offset;
let b = initial_b & bit_mask;
let mut stack_allocation = [0_u8; 8];
let size_blob = &mut stack_allocation[..atom_start_offset];
size_blob[0] = b;
Expand Down

0 comments on commit 47bb071

Please sign in to comment.