1
0
Fork 0
mirror of https://codeberg.org/icewind/bitbuffer.git synced 2026-06-03 16:44:06 +02:00
This commit is contained in:
Robin Appelman 2019-12-25 23:59:43 +01:00
commit 7290481a73
3 changed files with 9 additions and 25 deletions

View file

@ -9,4 +9,3 @@ matrix:
fast_finish: true
script:
- cargo test --all
- cargo test --all --all-features

View file

@ -20,6 +20,3 @@ memchr = "2.2"
maplit = "1.0.1"
[workspace]
[features]
unsafe = []

View file

@ -86,16 +86,6 @@ where
}
fn read_usize_bytes(&self, byte_index: usize) -> [u8; USIZE_SIZE] {
if cfg!(feature = "unsafe") {
use std::mem::transmute;
// panic instead of accessing out of bounds data when the caller didn't do it's job bounds checking
// due to the magic of branch prediction and this check "always" passing, the cost for this
// is below the point of being measurable by `cargo bench`
unsafe {
let ptr = self.bytes.as_ptr().add(byte_index);
*transmute::<_, &[u8; USIZE_SIZE]>(ptr)
}
} else {
if byte_index + USIZE_SIZE <= self.bytes.len() {
self.bytes[byte_index..byte_index + USIZE_SIZE]
.try_into()
@ -103,12 +93,10 @@ where
} else {
let mut bytes = [0; USIZE_SIZE];
let copy_bytes = self.bytes.len() - byte_index;
bytes[0..copy_bytes]
.copy_from_slice(&self.bytes[byte_index..byte_index + copy_bytes]);
bytes[0..copy_bytes].copy_from_slice(&self.bytes[byte_index..byte_index + copy_bytes]);
bytes
}
}
}
/// note that only the bottom USIZE - 1 bytes are usable
fn read_shifted_usize(&self, byte_index: usize, shift: usize) -> usize {