diff --git a/core/src/common/bit.rs b/core/src/common/bit.rs index 0c2bae835..c695b7acf 100644 --- a/core/src/common/bit.rs +++ b/core/src/common/bit.rs @@ -105,20 +105,6 @@ macro_rules! read_num_bytes { }}; } -/// u64 specific version of read_num_bytes! -/// This is faster than read_num_bytes! because this method avoids buffer copies. -#[inline] -pub fn read_num_bytes_u64(size: usize, src: &[u8]) -> u64 { - debug_assert!(size <= src.len()); - if unlikely(src.len() < 8) { - return read_num_bytes!(u64, size, src); - } - let in_ptr = src as *const [u8] as *const u8 as *const u64; - let v = unsafe { in_ptr.read_unaligned() }; - trailing_bits(v, size * 8) -} - - /// Similar to the `read_num_bytes` but read nums from bytes in big-endian order /// This is used to read bytes from Java's OutputStream which writes bytes in big-endian macro_rules! read_num_be_bytes { @@ -542,7 +528,7 @@ pub struct BitReader { impl BitReader { pub fn new(buf: Buffer, len: usize) -> Self { let num_bytes = cmp::min(8, len); - let buffered_values = read_num_bytes_u64(num_bytes, buf.as_slice()); + let buffered_values = read_num_bytes!(u64, num_bytes, buf.as_slice()); BitReader { buffer: buf, buffered_values, @@ -561,7 +547,7 @@ impl BitReader { self.buffer = buf; self.total_bytes = self.buffer.len(); let num_bytes = cmp::min(8, self.total_bytes); - self.buffered_values = read_num_bytes_u64(num_bytes, self.buffer.as_slice()); + self.buffered_values = read_num_bytes!(u64, num_bytes, self.buffer.as_slice()); self.byte_offset = 0; self.bit_offset = 0; } @@ -964,7 +950,7 @@ impl BitReader { fn reload_buffer_values(&mut self) { let bytes_to_read = cmp::min(self.total_bytes - self.byte_offset, 8); self.buffered_values = - read_num_bytes_u64(bytes_to_read, &self.buffer.as_slice()[self.byte_offset..]); + read_num_bytes!(u64, bytes_to_read, &self.buffer.as_slice()[self.byte_offset..]); } } @@ -996,17 +982,6 @@ mod tests { }; use std::fmt::Debug; - #[test] - fn test_read_num_bytes_u64() { - let buffer: Vec = vec![0, 1, 2, 3, 4, 5, 6, 7]; - for size in 0..buffer.len() { - assert_eq!( - read_num_bytes_u64(size, &buffer), - read_num_bytes!(u64, size, &buffer), - ); - } - } - #[test] fn test_ceil() { assert_eq!(ceil(0, 1), 0);