Skip to content

Commit 7ed768e

Browse files
committed
same branching reduction in BitVec::get_bits_unchecked
1 parent eba950d commit 7ed768e

File tree

1 file changed

+2
-4
lines changed

1 file changed

+2
-4
lines changed

src/bit_vec/mod.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -948,10 +948,8 @@ impl BitVec {
948948
pub fn get_bits_unchecked(&self, pos: usize, len: usize) -> u64 {
949949
debug_assert!(len <= WORD_SIZE);
950950
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)
951+
if pos % WORD_SIZE + len <= WORD_SIZE {
952+
partial_word & 1u64.checked_shl(len as u32).unwrap_or(0).wrapping_sub(1)
955953
} else {
956954
(partial_word | (self.data[pos / WORD_SIZE + 1] << (WORD_SIZE - pos % WORD_SIZE)))
957955
& 1u64.checked_shl(len as u32).unwrap_or(0).wrapping_sub(1)

0 commit comments

Comments
 (0)