Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix cargo clippy warnings.
Browse files Browse the repository at this point in the history
anforowicz committed Jan 13, 2025

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent ccda95b commit 81dee58
Showing 3 changed files with 18 additions and 17 deletions.
21 changes: 11 additions & 10 deletions src/decompress.rs
Original file line number Diff line number Diff line change
@@ -228,11 +228,11 @@ impl Decompressor {
}

let input0 = self.bits.peek_bits(8);
let input1 = self.bits.peek_bits(16) >> 8 & 0xff;
let input1 = (self.bits.peek_bits(16) >> 8) & 0xff;
if input0 & 0x0f != 0x08
|| (input0 & 0xf0) > 0x70
|| input1 & 0x20 != 0
|| (input0 << 8 | input1) % 31 != 0
|| ((input0 << 8) | input1) % 31 != 0
{
return Err(DecompressionError::BadZlibHeader);
}
@@ -623,9 +623,9 @@ impl<const LITLEN_TABLE_SIZE: usize, const DIST_TABLE_SIZE: usize>
assert!(LITLEN_TABLE_SIZE.count_ones() == 1);
assert!(DIST_TABLE_SIZE.count_ones() == 1);
let litlen_table_mask = (LITLEN_TABLE_SIZE as u64) - 1;
let litlen_table_bits = LITLEN_TABLE_SIZE.trailing_zeros() as u32;
let litlen_table_bits = LITLEN_TABLE_SIZE.trailing_zeros();
let dist_table_mask = (DIST_TABLE_SIZE as u64) - 1;
let dist_table_bits = DIST_TABLE_SIZE.trailing_zeros() as u32;
let dist_table_bits = DIST_TABLE_SIZE.trailing_zeros();
// Lower bound on table sizes, because 1a) RFC1951 uses at most 15 bits for codewords and
// 1b) we can fit at most 8 bits of `overflow_bits_mask` in the last byte of a primary
// table entry.
@@ -653,14 +653,15 @@ impl<const LITLEN_TABLE_SIZE: usize, const DIST_TABLE_SIZE: usize>
let mut litlen_code_bits = litlen_entry as u8;
if litlen_entry & LITERAL_ENTRY != 0 {
let litlen_entry2 = self.litlen_table
[(bit_buffer.buffer >> litlen_code_bits & litlen_table_mask) as usize];
[((bit_buffer.buffer >> litlen_code_bits) & litlen_table_mask) as usize];
let litlen_code_bits2 = litlen_entry2 as u8;
let litlen_entry3 =
self.litlen_table[(bit_buffer.buffer >> (litlen_code_bits + litlen_code_bits2)
& litlen_table_mask) as usize];
let litlen_entry3 = self.litlen_table[((bit_buffer.buffer
>> (litlen_code_bits + litlen_code_bits2))
& litlen_table_mask)
as usize];
let litlen_code_bits3 = litlen_entry3 as u8;
let litlen_entry4 = self.litlen_table[(bit_buffer.buffer
>> (litlen_code_bits + litlen_code_bits2 + litlen_code_bits3)
let litlen_entry4 = self.litlen_table[((bit_buffer.buffer
>> (litlen_code_bits + litlen_code_bits2 + litlen_code_bits3))
& litlen_table_mask)
as usize];

4 changes: 2 additions & 2 deletions src/huffman.rs
Original file line number Diff line number Diff line change
@@ -118,8 +118,8 @@ pub fn build_table(
let codeword1 = codes[sym1];
let codeword2 = codes[sym2];
let codeword = codeword1 | (codeword2 << len1);
let entry = (sym1 as u32) << 16
| (sym2 as u32) << 24
let entry = ((sym1 as u32) << 16)
| ((sym2 as u32) << 24)
| LITERAL_ENTRY
| (2 << 8);
primary_table[codeword as usize] = entry | (length as u32);
10 changes: 5 additions & 5 deletions src/tables.rs
Original file line number Diff line number Diff line change
@@ -104,7 +104,7 @@ pub(crate) const LITLEN_TABLE_ENTRIES: [u32; 288] = {
// 00000000_iiiiiiii_10000001_0000???? (? = will be filled by huffman::build_table)
// aaaaaaaa_bbbbbbbb_100000yy_0000xxxx
// x = input_advance_bits, y = output_advance_bytes (literal)
entries[i] = (i as u32) << 16 | LITERAL_ENTRY | (1 << 8);
entries[i] = ((i as u32) << 16) | LITERAL_ENTRY | (1 << 8);
i += 1;
}

@@ -114,8 +114,8 @@ pub(crate) const LITLEN_TABLE_ENTRIES: [u32; 288] = {
// 0000000z_zzzzzzzz_00000yyy_0000???? (? = will be filled by huffman::build_table)
// 0000000z_zzzzzzzz_00000yyy_0000xxxx
// x = input_advance_bits, y = extra_bits, z = distance_base (length)
entries[i] = (LEN_SYM_TO_LEN_BASE[i - 257] as u32) << 16
| (LEN_SYM_TO_LEN_EXTRA[i - 257] as u32) << 8;
entries[i] = ((LEN_SYM_TO_LEN_BASE[i - 257] as u32) << 16)
| ((LEN_SYM_TO_LEN_EXTRA[i - 257] as u32) << 8);
i += 1;
}
entries
@@ -131,8 +131,8 @@ pub(crate) const DISTANCE_TABLE_ENTRIES: [u32; 32] = {
let mut entries = [0; 32];
let mut i = 0;
while i < 30 {
entries[i] = (DIST_SYM_TO_DIST_BASE[i] as u32) << 16
| (DIST_SYM_TO_DIST_EXTRA[i] as u32) << 8
entries[i] = ((DIST_SYM_TO_DIST_BASE[i] as u32) << 16)
| ((DIST_SYM_TO_DIST_EXTRA[i] as u32) << 8)
| LITERAL_ENTRY;
i += 1;
}

0 comments on commit 81dee58

Please sign in to comment.