Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
add inline mark to IterUXDigits
  • Loading branch information
Speedy37 authored and cuviper committed Feb 24, 2021
commit aeb8e302dd5ad02ff7b677015f0b48703d967c07
26 changes: 26 additions & 0 deletions src/biguint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2303,6 +2303,7 @@ pub struct IterU32Digits<'a> {
}
#[cfg(u64_digit)]
impl<'a> IterU32Digits<'a> {
#[inline]
fn new(data: &'a [u64]) -> Self {
let last_hi_is_zero = data
.last()
Expand All @@ -2321,6 +2322,7 @@ impl<'a> IterU32Digits<'a> {
#[cfg(u64_digit)]
impl Iterator for IterU32Digits<'_> {
type Item = u32;
#[inline]
fn next(&mut self) -> Option<u32> {
match self.data.split_first() {
Some((&first, data)) => {
Expand All @@ -2342,11 +2344,13 @@ impl Iterator for IterU32Digits<'_> {
}
}

#[inline]
fn size_hint(&self) -> (usize, Option<usize>) {
let len = self.len();
(len, Some(len))
}

#[inline]
fn last(self) -> Option<u32> {
self.data.last().map(|&last| {
if self.last_hi_is_zero {
Expand All @@ -2357,48 +2361,57 @@ impl Iterator for IterU32Digits<'_> {
})
}

#[inline]
fn count(self) -> usize {
self.len()
}
}
#[cfg(u64_digit)]
impl ExactSizeIterator for IterU32Digits<'_> {
#[inline]
fn len(&self) -> usize {
self.data.len() * 2 - usize::from(self.last_hi_is_zero) - usize::from(!self.next_is_lo)
}
}

#[cfg(not(u64_digit))]
impl<'a> IterU32Digits<'a> {
#[inline]
fn new(data: &'a [u32]) -> Self {
Self { it: data.iter() }
}
}
#[cfg(not(u64_digit))]
impl Iterator for IterU32Digits<'_> {
type Item = u32;
#[inline]
fn next(&mut self) -> Option<u32> {
self.it.next().cloned()
}

#[inline]
fn size_hint(&self) -> (usize, Option<usize>) {
self.it.size_hint()
}

#[inline]
fn nth(&mut self, n: usize) -> Option<u32> {
self.it.nth(n).cloned()
}

#[inline]
fn last(self) -> Option<u32> {
self.it.last().cloned()
}

#[inline]
fn count(self) -> usize {
self.it.count()
}
}
#[cfg(not(u64_digit))]
impl ExactSizeIterator for IterU32Digits<'_> {
#[inline]
fn len(&self) -> usize {
self.it.len()
}
Expand All @@ -2417,6 +2430,7 @@ pub struct IterU64Digits<'a> {
}
#[cfg(not(u64_digit))]
impl<'a> IterU64Digits<'a> {
#[inline]
fn new(data: &'a [u32]) -> Self {
IterU64Digits { it: data.chunks(2) }
}
Expand All @@ -2425,61 +2439,73 @@ impl<'a> IterU64Digits<'a> {
#[cfg(not(u64_digit))]
impl Iterator for IterU64Digits<'_> {
type Item = u64;
#[inline]
fn next(&mut self) -> Option<u64> {
self.it.next().map(u32_chunk_to_u64)
}

#[inline]
fn size_hint(&self) -> (usize, Option<usize>) {
let len = self.len();
(len, Some(len))
}

#[inline]
fn last(self) -> Option<u64> {
self.it.last().map(u32_chunk_to_u64)
}

#[inline]
fn count(self) -> usize {
self.len()
}
}
#[cfg(not(u64_digit))]
impl ExactSizeIterator for IterU64Digits<'_> {
#[inline]
fn len(&self) -> usize {
self.it.len()
}
}

#[cfg(u64_digit)]
impl<'a> IterU64Digits<'a> {
#[inline]
fn new(data: &'a [u64]) -> Self {
Self { it: data.iter() }
}
}
#[cfg(u64_digit)]
impl Iterator for IterU64Digits<'_> {
type Item = u64;
#[inline]
fn next(&mut self) -> Option<u64> {
self.it.next().cloned()
}

#[inline]
fn size_hint(&self) -> (usize, Option<usize>) {
self.it.size_hint()
}

#[inline]
fn nth(&mut self, n: usize) -> Option<u64> {
self.it.nth(n).cloned()
}

#[inline]
fn last(self) -> Option<u64> {
self.it.last().cloned()
}

#[inline]
fn count(self) -> usize {
self.it.count()
}
}
#[cfg(u64_digit)]
impl ExactSizeIterator for IterU64Digits<'_> {
#[inline]
fn len(&self) -> usize {
self.it.len()
}
Expand Down