From dd2ace77f652510a680fdfd21a08361cbb905702 Mon Sep 17 00:00:00 2001 From: Cong-Cong Date: Thu, 2 Jan 2025 10:13:47 +0800 Subject: [PATCH] perf: current_value use usize --- src/decoder.rs | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/src/decoder.rs b/src/decoder.rs index 46229241..c92fdfa3 100644 --- a/src/decoder.rs +++ b/src/decoder.rs @@ -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, } @@ -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; } }