Skip to content

Commit

Permalink
Use trailing_ones
Browse files Browse the repository at this point in the history
  • Loading branch information
cuviper committed Feb 8, 2024
1 parent 27a3a65 commit 9c1c9ab
Showing 1 changed file with 1 addition and 4 deletions.
5 changes: 1 addition & 4 deletions src/biguint.rs
Expand Up @@ -906,10 +906,7 @@ impl BigUint {
/// Returns the number of least-significant bits that are ones.
pub fn trailing_ones(&self) -> u64 {
if let Some(i) = self.data.iter().position(|&digit| !digit != 0) {
// XXX u64::trailing_ones() introduced in Rust 1.46,
// but we need to be compatible further back.
// Thanks to cuviper for this workaround.
let ones: u64 = (!self.data[i]).trailing_zeros().into();
let ones: u64 = self.data[i].trailing_ones().into();
i as u64 * u64::from(big_digit::BITS) + ones
} else {
self.data.len() as u64 * u64::from(big_digit::BITS)
Expand Down

0 comments on commit 9c1c9ab

Please sign in to comment.