Skip to content

Commit 5326052

Browse files
committed
silenced a bunch of misleading Clippy warnings; fixed a possible performance bug
* There were a bunch of code quality Clippy warnings that didn't apply for various reasons. * There was an ok_or() that should have been an ok_or_else().
1 parent 92b8f48 commit 5326052

File tree

4 files changed

+15
-2
lines changed

4 files changed

+15
-2
lines changed

src/algorithms.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,7 @@ fn bigint_from_slice(slice: &[BigDigit]) -> BigInt {
347347
BigInt::from(biguint_from_vec(slice.to_vec()))
348348
}
349349

350+
#[allow(clippy::many_single_char_names)]
350351
/// Three argument multiply accumulate:
351352
/// acc += b * c
352353
fn mac3(acc: &mut [BigDigit], b: &[BigDigit], c: &[BigDigit]) {

src/bigint.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2707,7 +2707,9 @@ impl TryFrom<&BigInt> for BigUint {
27072707

27082708
#[inline]
27092709
fn try_from(value: &BigInt) -> Result<BigUint, TryFromBigIntError<()>> {
2710-
value.to_biguint().ok_or(TryFromBigIntError::new(()))
2710+
value
2711+
.to_biguint()
2712+
.ok_or_else(|| TryFromBigIntError::new(()))
27112713
}
27122714
}
27132715

src/biguint.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1811,10 +1811,15 @@ impl Roots for BigUint {
18111811
}
18121812
}
18131813

1814+
#[allow(clippy::useless_conversion)]
18141815
fn high_bits_to_u64(v: &BigUint) -> u64 {
18151816
match v.data.len() {
18161817
0 => 0,
1817-
1 => u64::from(v.data[0]),
1818+
1 =>
1819+
{
1820+
#[allow(clippy::useless_conversion)]
1821+
u64::from(v.data[0])
1822+
}
18181823
_ => {
18191824
let mut bits = v.bits();
18201825
let mut ret = 0u64;
@@ -1827,6 +1832,7 @@ fn high_bits_to_u64(v: &BigUint) -> u64 {
18271832
if bits_want != 64 {
18281833
ret <<= bits_want;
18291834
}
1835+
// XXX Conversion is useless if already 64-bit.
18301836
ret |= u64::from(*d) >> (digit_bits - bits_want);
18311837
ret_bits += bits_want;
18321838
bits -= bits_want;
@@ -1852,6 +1858,7 @@ impl ToPrimitive for BigUint {
18521858
self.to_u128().as_ref().and_then(u128::to_i128)
18531859
}
18541860

1861+
#[allow(clippy::useless_conversion)]
18551862
#[inline]
18561863
fn to_u64(&self) -> Option<u64> {
18571864
let mut ret: u64 = 0;
@@ -1862,6 +1869,7 @@ impl ToPrimitive for BigUint {
18621869
return None;
18631870
}
18641871

1872+
// XXX Conversion is useless if already 64-bit.
18651873
ret += u64::from(*i) << bits;
18661874
bits += big_digit::BITS;
18671875
}

src/monty.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ impl MontyReducer {
3434
}
3535
}
3636

37+
#[allow(clippy::many_single_char_names)]
3738
/// Computes z mod m = x * y * 2 ** (-n*_W) mod m
3839
/// assuming k = -1/m mod 2**_W
3940
/// See Gueron, "Efficient Software Implementations of Modular Exponentiation".
@@ -130,6 +131,7 @@ fn mul_add_www(x: BigDigit, y: BigDigit, c: BigDigit) -> (BigDigit, BigDigit) {
130131
((z >> big_digit::BITS) as BigDigit, z as BigDigit)
131132
}
132133

134+
#[allow(clippy::many_single_char_names)]
133135
/// Calculates x ** y mod m using a fixed, 4-bit window.
134136
pub(crate) fn monty_modpow(x: &BigUint, y: &BigUint, m: &BigUint) -> BigUint {
135137
assert!(m.data[0] & 1 == 1);

0 commit comments

Comments
 (0)