mirror of
https://codeberg.org/icewind/bitbuffer.git
synced 2026-06-03 16:44:06 +02:00
faster byte_index
this can overflow the buffer when reading the initial bytes, but we'll only uses the bytes that are part of the stream
This commit is contained in:
parent
589928921e
commit
efcf31d596
1 changed files with 2 additions and 3 deletions
|
|
@ -86,11 +86,10 @@ impl<E> BitBuffer<E>
|
|||
}
|
||||
|
||||
fn read_usize(&self, position: usize, count: usize) -> Result<usize> {
|
||||
let byte_index = min(position / 8, self.byte_len - USIZE_SIZE);
|
||||
let byte_index = position / 8;
|
||||
let bit_offset = position - byte_index * 8;
|
||||
let raw_container: &usize = unsafe {
|
||||
// this is safe here because it's already verified that there is enough data in the slice
|
||||
// to read a usize from byte_index
|
||||
// this is safe here because we already have checks that we don't read past the slice
|
||||
let ptr = self.bytes.as_ptr().add(byte_index);
|
||||
std::mem::transmute(ptr)
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue