Skip to content

Commit

Permalink
Use an iterator and slice approach to trim zeros
Browse files Browse the repository at this point in the history
  • Loading branch information
fbernier committed Feb 24, 2025
1 parent 59f24f1 commit f2b961c
Showing 1 changed file with 2 additions and 5 deletions.
7 changes: 2 additions & 5 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -345,11 +345,8 @@ fn decode_impl(mut input: &[u8], decode_table: &[u8; 256]) -> Result<u128, Decod
}

// Remove leading zeroes
let mut chopped_count = 0_usize;
while let Option::Some(b'0') = input.first() {
input = &input[1..];
chopped_count += 1;
}
let chopped_count = input.iter().take_while(|&&ch| ch == b'0').count();
input = &input[chopped_count..];

let input_len = input.len();
if input_len <= 22 {
Expand Down

0 comments on commit f2b961c

Please sign in to comment.