We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent eba950d commit 7ed768eCopy full SHA for 7ed768e
src/bit_vec/mod.rs
@@ -948,10 +948,8 @@ impl BitVec {
948
pub fn get_bits_unchecked(&self, pos: usize, len: usize) -> u64 {
949
debug_assert!(len <= WORD_SIZE);
950
let partial_word = self.data[pos / WORD_SIZE] >> (pos % WORD_SIZE);
951
- if pos % WORD_SIZE + len == WORD_SIZE {
952
- partial_word
953
- } else if pos % WORD_SIZE + len < WORD_SIZE {
954
- partial_word & ((1 << (len % WORD_SIZE)) - 1)
+ if pos % WORD_SIZE + len <= WORD_SIZE {
+ partial_word & 1u64.checked_shl(len as u32).unwrap_or(0).wrapping_sub(1)
955
} else {
956
(partial_word | (self.data[pos / WORD_SIZE + 1] << (WORD_SIZE - pos % WORD_SIZE)))
957
& 1u64.checked_shl(len as u32).unwrap_or(0).wrapping_sub(1)
0 commit comments