Skip to content

Commit

Permalink
remove casting noise around drop_bits
Browse files Browse the repository at this point in the history
  • Loading branch information
folkertdev committed Sep 19, 2024
1 parent 9b5a343 commit 4d3ff06
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 18 deletions.
32 changes: 16 additions & 16 deletions zlib-rs/src/inflate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1122,11 +1122,11 @@ impl<'a> State<'a> {
pull_byte!(self);
}

self.bit_reader.drop_bits(last.bits as usize);
self.bit_reader.drop_bits(last.bits);
self.back += last.bits as usize;
}

self.bit_reader.drop_bits(here.bits as usize);
self.bit_reader.drop_bits(here.bits);
self.back += here.bits as usize;
self.length = here.val as usize;

Expand Down Expand Up @@ -1159,7 +1159,7 @@ impl<'a> State<'a> {
if extra != 0 {
need_bits!(self, extra);
self.length += self.bit_reader.bits(extra) as usize;
self.bit_reader.drop_bits(extra);
self.bit_reader.drop_bits(extra as u8);
self.back += extra;
}

Expand Down Expand Up @@ -1197,11 +1197,11 @@ impl<'a> State<'a> {
pull_byte!(self);
}

self.bit_reader.drop_bits(last.bits as usize);
self.bit_reader.drop_bits(last.bits);
self.back += last.bits as usize;
}

self.bit_reader.drop_bits(here.bits as usize);
self.bit_reader.drop_bits(here.bits);

if here.op & 64 != 0 {
self.mode = Mode::Bad;
Expand All @@ -1221,7 +1221,7 @@ impl<'a> State<'a> {
if extra > 0 {
need_bits!(self, extra);
self.offset += self.bit_reader.bits(extra) as usize;
self.bit_reader.drop_bits(extra);
self.bit_reader.drop_bits(extra as u8);
self.back += extra;
}

Expand Down Expand Up @@ -1378,7 +1378,7 @@ impl<'a> State<'a> {
pull_byte!(self);
};

let here_bits = here.bits as usize;
let here_bits = here.bits;

match here.val {
0..=15 => {
Expand All @@ -1387,7 +1387,7 @@ impl<'a> State<'a> {
self.have += 1;
}
16 => {
need_bits!(self, here_bits + 2);
need_bits!(self, here_bits as usize + 2);
self.bit_reader.drop_bits(here_bits);
if self.have == 0 {
self.mode = Mode::Bad;
Expand All @@ -1409,7 +1409,7 @@ impl<'a> State<'a> {
}
}
17 => {
need_bits!(self, here_bits + 3);
need_bits!(self, here_bits as usize + 3);
self.bit_reader.drop_bits(here_bits);
let len = 0;
let copy = 3 + self.bit_reader.bits(3) as usize;
Expand All @@ -1426,7 +1426,7 @@ impl<'a> State<'a> {
}
}
18.. => {
need_bits!(self, here_bits + 7);
need_bits!(self, here_bits as usize + 7);
self.bit_reader.drop_bits(here_bits);
let len = 0;
let copy = 11 + self.bit_reader.bits(7) as usize;
Expand Down Expand Up @@ -1587,26 +1587,26 @@ fn inflate_fast_help(state: &mut State, _start: usize) -> ReturnCode {

if here.op == 0 {
writer.push(here.val as u8);
bit_reader.drop_bits(here.bits as usize);
bit_reader.drop_bits(here.bits);
here = lcode[(bit_reader.hold() & lmask) as usize];

if here.op == 0 {
writer.push(here.val as u8);
bit_reader.drop_bits(here.bits as usize);
bit_reader.drop_bits(here.bits);
here = lcode[(bit_reader.hold() & lmask) as usize];
}
}

'dolen: loop {
bit_reader.drop_bits(here.bits as usize);
bit_reader.drop_bits(here.bits);
let op = here.op;

if op == 0 {
writer.push(here.val as u8);
} else if op & 16 != 0 {
let op = op & MAX_BITS;
let mut len = here.val + bit_reader.bits(op as usize) as u16;
bit_reader.drop_bits(op as usize);
bit_reader.drop_bits(op);

here = dcode[(bit_reader.hold() & dmask) as usize];

Expand All @@ -1617,7 +1617,7 @@ fn inflate_fast_help(state: &mut State, _start: usize) -> ReturnCode {
}

'dodist: loop {
bit_reader.drop_bits(here.bits as usize);
bit_reader.drop_bits(here.bits);
let op = here.op;

if op & 16 != 0 {
Expand All @@ -1630,7 +1630,7 @@ fn inflate_fast_help(state: &mut State, _start: usize) -> ReturnCode {
break 'outer;
}

bit_reader.drop_bits(op as usize);
bit_reader.drop_bits(op);

// max distance in output
let written = writer.len();
Expand Down
4 changes: 2 additions & 2 deletions zlib-rs/src/inflate/bitreader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,9 @@ impl<'a> BitReader<'a> {
}

#[inline(always)]
pub fn drop_bits(&mut self, n: usize) {
pub fn drop_bits(&mut self, n: u8) {
self.bit_buffer >>= n;
self.bits_used -= n as u8;
self.bits_used -= n;
}

#[inline(always)]
Expand Down

0 comments on commit 4d3ff06

Please sign in to comment.