Skip to content

Commit eba950d

Browse files
committed
reduced branching in get_bits, improving performance of various data structures
1 parent 803e865 commit eba950d

File tree

1 file changed

+2
-4
lines changed

1 file changed

+2
-4
lines changed

src/bit_vec/fast_rs_vec/mod.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -373,10 +373,8 @@ impl RsVec {
373373
pub fn get_bits_unchecked(&self, pos: usize, len: usize) -> u64 {
374374
debug_assert!(len <= WORD_SIZE);
375375
let partial_word = self.data[pos / WORD_SIZE] >> (pos % WORD_SIZE);
376-
if pos % WORD_SIZE + len == WORD_SIZE {
377-
partial_word
378-
} else if pos % WORD_SIZE + len < WORD_SIZE {
379-
partial_word & ((1 << (len % WORD_SIZE)) - 1)
376+
if pos % WORD_SIZE + len <= WORD_SIZE {
377+
partial_word & 1u64.checked_shl(len as u32).unwrap_or(0).wrapping_sub(1)
380378
} else {
381379
(partial_word | (self.data[pos / WORD_SIZE + 1] << (WORD_SIZE - pos % WORD_SIZE)))
382380
& 1u64.checked_shl(len as u32).unwrap_or(0).wrapping_sub(1)

0 commit comments

Comments
 (0)