Skip to content

Commit

Permalink
Add BitIter::new().
Browse files Browse the repository at this point in the history
This factors out some duplicated code.
  • Loading branch information
nnethercote committed Oct 15, 2019
1 parent 237d54f commit 2918a7d
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions src/librustc_index/bit_set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,11 +168,7 @@ impl<T: Idx> BitSet<T> {
/// Iterates over the indices of set bits in a sorted order.
#[inline]
pub fn iter(&self) -> BitIter<'_, T> {
BitIter {
cur: None,
iter: self.words.iter().enumerate(),
marker: PhantomData,
}
BitIter::new(&self.words)
}

/// Duplicates the set as a hybrid set.
Expand Down Expand Up @@ -296,6 +292,17 @@ pub struct BitIter<'a, T: Idx> {
marker: PhantomData<T>
}

impl<'a, T: Idx> BitIter<'a, T> {
#[inline]
fn new(words: &'a [Word]) -> BitIter<'a, T> {
BitIter {
cur: None,
iter: words.iter().enumerate(),
marker: PhantomData,
}
}
}

impl<'a, T: Idx> Iterator for BitIter<'a, T> {
type Item = T;
fn next(&mut self) -> Option<T> {
Expand Down Expand Up @@ -851,11 +858,7 @@ impl<R: Idx, C: Idx> BitMatrix<R, C> {
pub fn iter(&self, row: R) -> BitIter<'_, C> {
assert!(row.index() < self.num_rows);
let (start, end) = self.range(row);
BitIter {
cur: None,
iter: self.words[start..end].iter().enumerate(),
marker: PhantomData,
}
BitIter::new(&self.words[start..end])
}

/// Returns the number of elements in `row`.
Expand Down

0 comments on commit 2918a7d

Please sign in to comment.