Skip to content

Commit

Permalink
perf: current_value use usize
Browse files Browse the repository at this point in the history
  • Loading branch information
SyMind committed Jan 2, 2025
1 parent 212bbc8 commit dd2ace7
Showing 1 changed file with 8 additions and 11 deletions.
19 changes: 8 additions & 11 deletions src/decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ pub(crate) struct MappingsDecoder<'a> {
current_data: [u32; 5],
current_data_pos: usize,
// current_value will include a sign bit at bit 0
current_value: i64,
current_value: usize,
current_value_pos: usize,
generated_line: u32,
}
Expand Down Expand Up @@ -103,23 +103,20 @@ impl Iterator for MappingsDecoder<'_> {
}
} else if (value & CONTINUATION_BIT) == 0 {
// last sextet
self.current_value |= (value as i64) << self.current_value_pos;
let final_value = if (self.current_value & 1) != 0 {
-(self.current_value >> 1)
} else {
self.current_value >> 1
};
self.current_value |= (value as usize) << self.current_value_pos;
if self.current_data_pos < 5 {
self.current_data[self.current_data_pos] =
(self.current_data[self.current_data_pos] as i64 + final_value)
as u32;
self.current_data[self.current_data_pos] = if (self.current_value & 1) != 0 {
self.current_data[self.current_data_pos] as usize - (self.current_value >> 1)
} else {
self.current_data[self.current_data_pos] as usize + (self.current_value >> 1)
} as u32;
}
self.current_data_pos += 1;
self.current_value_pos = 0;
self.current_value = 0;
} else {
self.current_value |=
((value & DATA_MASK) as i64) << self.current_value_pos;
((value & DATA_MASK) as usize) << self.current_value_pos;
self.current_value_pos += 5;
}
}
Expand Down

0 comments on commit dd2ace7

Please sign in to comment.