Skip to content

Commit b0bed64

Browse files
Speedy37cuviper
authored andcommitted
fix 32bits build
1 parent 51a94c5 commit b0bed64

File tree

1 file changed

+18
-25
lines changed

1 file changed

+18
-25
lines changed

src/biguint.rs

Lines changed: 18 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,17 @@ impl FromStr for BigUint {
176176
}
177177
}
178178

179+
/// Convert a u32 chunk (len is either 1 or 2) to a single u64 digit
180+
#[inline]
181+
fn u32_chunk_to_u64(chunk: &[u32]) -> u64 {
182+
// raw could have odd length
183+
let mut digit = chunk[0] as u64;
184+
if let Some(&hi) = chunk.get(1) {
185+
digit |= (hi as u64) << 32;
186+
}
187+
digit
188+
}
189+
179190
// Convert from a power of two radix (bits == ilog2(radix)) where bits evenly divides
180191
// BigDigit::BITS
181192
fn from_bitwise_digits_le(v: &[u8], bits: u8) -> BigUint {
@@ -2399,35 +2410,24 @@ pub struct IterU64Digits<'a> {
23992410
#[cfg(not(u64_digit))]
24002411
impl<'a> IterU64Digits<'a> {
24012412
fn new(data: &'a [u32]) -> Self {
2402-
IterU32Digits { it: data.chunks(2) }
2413+
IterU64Digits { it: data.chunks(2) }
24032414
}
24042415
}
2416+
24052417
#[cfg(not(u64_digit))]
24062418
impl<'a> Iterator for IterU64Digits<'a> {
24072419
type Item = u64;
24082420
fn next(&mut self) -> Option<u64> {
2409-
self.it.next(|chunk| {
2410-
let mut digit = chunk[0] as u64;
2411-
if let Some(&hi) = chunk.get(1) {
2412-
digit |= (hi as u64) << 32;
2413-
}
2414-
digit
2415-
})
2421+
self.it.next().map(u32_chunk_to_u64)
24162422
}
24172423

24182424
fn size_hint(&self) -> (usize, Option<usize>) {
24192425
let len = self.len();
24202426
(len, Some(len))
24212427
}
24222428

2423-
fn last(self) -> Option<u32> {
2424-
self.data.last().map(|&last| {
2425-
if self.last_hi_is_zero {
2426-
last as u32
2427-
} else {
2428-
(last >> 32) as u32
2429-
}
2430-
})
2429+
fn last(self) -> Option<u64> {
2430+
self.it.last().map(u32_chunk_to_u64)
24312431
}
24322432

24332433
fn count(self) -> usize {
@@ -2437,7 +2437,7 @@ impl<'a> Iterator for IterU64Digits<'a> {
24372437
#[cfg(not(u64_digit))]
24382438
impl<'a> ExactSizeIterator for IterU64Digits<'a> {
24392439
fn len(&self) -> usize {
2440-
self.data.len() * 2 - usize::from(self.last_hi_is_zero)
2440+
self.it.len()
24412441
}
24422442
}
24432443

@@ -2531,14 +2531,7 @@ impl BigUint {
25312531
self.data.extend_from_slice(slice);
25322532

25332533
#[cfg(u64_digit)]
2534-
self.data.extend(slice.chunks(2).map(|chunk| {
2535-
// raw could have odd length
2536-
let mut digit = BigDigit::from(chunk[0]);
2537-
if let Some(&hi) = chunk.get(1) {
2538-
digit |= BigDigit::from(hi) << 32;
2539-
}
2540-
digit
2541-
}));
2534+
self.data.extend(slice.chunks(2).map(u32_chunk_to_u64));
25422535

25432536
self.normalize();
25442537
}

0 commit comments

Comments
 (0)