-
-
Notifications
You must be signed in to change notification settings - Fork 9
decompress.rs: faster input reading
#85
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
eb01ae8
12c1e76
df1b941
97f5d92
8efb89a
1ca350f
0a58925
c78469e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -244,6 +244,35 @@ mod stream { | |
| unsafe { Allocator::from_bz_stream(self) } | ||
| } | ||
|
|
||
| #[must_use] | ||
| #[inline(always)] | ||
| pub(crate) fn pull_u32( | ||
| &mut self, | ||
| mut bit_buffer: u32, | ||
| bits_used: i32, | ||
| ) -> Option<(u32, i32)> { | ||
| if self.avail_in < 4 { | ||
| return None; | ||
| } | ||
|
|
||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe add a debug assertion that no more than 7 bytes are requested? And no more than 1 byte in the case of pull_u8.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. well I added an assert that we can at least consume 1 additional byte, in other words that we don't ask for more input if we don't have space in the bit buffer. The check you comment on is a bounds check, so we just skip this function if there are not 8 additional bytes in the input, there is nothing to assert there right? |
||
| // of course this uses big endian values | ||
| let read = unsafe { self.next_in.cast::<u32>().read_unaligned().to_be() }; | ||
folkertdev marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| // because of the endianness, we can only shift in whole bytes. | ||
| let increment_bytes = (31 - bits_used) / 8; | ||
| let increment_bits = 8 * increment_bytes; | ||
|
|
||
| bit_buffer <<= increment_bits; | ||
| bit_buffer |= read >> (32 - increment_bits); | ||
|
|
||
| self.next_in = unsafe { (self.next_in).add(increment_bytes as usize) }; | ||
| self.avail_in -= increment_bytes as u32; | ||
|
|
||
| // skips updating `self.total_in`: the caller is responsible for keeping it updated | ||
folkertdev marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| Some((bit_buffer, bits_used + increment_bits)) | ||
| } | ||
|
|
||
| #[must_use] | ||
| #[inline(always)] | ||
| pub(crate) fn read_byte_fast(&mut self) -> Option<u8> { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.