Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions zlib-rs/src/inflate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -532,7 +532,10 @@ impl State<'_> {

if avail_in >= INFLATE_FAST_MIN_HAVE && avail_out >= INFLATE_FAST_MIN_LEFT {
inflate_fast_help(self, 0);
return None;
match self.mode {
Mode::Len => {}
_ => return None,
}
}

let mut mode;
Expand Down Expand Up @@ -2027,7 +2030,8 @@ fn inflate_fast_help(state: &mut State, _start: usize) {
break 'dolen;
}

let remaining = bit_reader.bytes_remaining();
// include the bits in the bit_reader buffer in the count of available bytes
let remaining = bit_reader.bytes_remaining_including_buffer();
if remaining >= INFLATE_FAST_MIN_HAVE && writer.remaining() >= INFLATE_FAST_MIN_LEFT {
continue;
}
Expand Down
5 changes: 5 additions & 0 deletions zlib-rs/src/inflate/bitreader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,11 @@ impl<'a> BitReader<'a> {
self.end as usize - self.ptr as usize
}

#[inline(always)]
pub fn bytes_remaining_including_buffer(&self) -> usize {
(self.end as usize - self.ptr as usize) + (self.bits_used as usize >> 3)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using / 8 instead of >> 3 may be a bit clearer and will optimize to the same assembly.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can make a pass over the repo at some point. I think zlib-ng never updated this, and the original zlib that it forked was written at a time when apparently that optimization was not (effectively) guaranteed.

}

#[inline(always)]
pub fn need_bits(&mut self, n: usize) -> Result<(), ReturnCode> {
while (self.bits_used as usize) < n {
Expand Down