Skip to content

Commit ad0dbf8

Browse files
committed
Add BitIter::new().
This factors out some duplicated code.
1 parent 20cc752 commit ad0dbf8

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed

src/librustc_index/bit_set.rs

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -168,11 +168,7 @@ impl<T: Idx> BitSet<T> {
168168
/// Iterates over the indices of set bits in a sorted order.
169169
#[inline]
170170
pub fn iter(&self) -> BitIter<'_, T> {
171-
BitIter {
172-
cur: None,
173-
iter: self.words.iter().enumerate(),
174-
marker: PhantomData,
175-
}
171+
BitIter::new(&self.words)
176172
}
177173

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

295+
impl<'a, T: Idx> BitIter<'a, T> {
296+
#[inline]
297+
fn new(words: &'a [Word]) -> BitIter<'a, T> {
298+
BitIter {
299+
cur: None,
300+
iter: words.iter().enumerate(),
301+
marker: PhantomData,
302+
}
303+
}
304+
}
305+
299306
impl<'a, T: Idx> Iterator for BitIter<'a, T> {
300307
type Item = T;
301308
fn next(&mut self) -> Option<T> {
@@ -851,11 +858,7 @@ impl<R: Idx, C: Idx> BitMatrix<R, C> {
851858
pub fn iter(&self, row: R) -> BitIter<'_, C> {
852859
assert!(row.index() < self.num_rows);
853860
let (start, end) = self.range(row);
854-
BitIter {
855-
cur: None,
856-
iter: self.words[start..end].iter().enumerate(),
857-
marker: PhantomData,
858-
}
861+
BitIter::new(&self.words[start..end])
859862
}
860863

861864
/// Returns the number of elements in `row`.

0 commit comments

Comments
 (0)