]> git.lizzy.rs Git - rust.git/commitdiff
Remove `Iter` and `SparseIter` in indexed_set.rs.
authorNicholas Nethercote <nnethercote@mozilla.com>
Thu, 13 Sep 2018 22:06:52 +0000 (08:06 +1000)
committerNicholas Nethercote <nnethercote@mozilla.com>
Thu, 13 Sep 2018 22:51:31 +0000 (08:51 +1000)
Because they're just thin wrappers around `BitIter` and `slice::Iter`.

src/librustc_data_structures/indexed_set.rs
src/librustc_mir/borrow_check/flows.rs
src/librustc_mir/dataflow/at_location.rs

index be519e7bbdeb7485d53958596af007da5cbb3302..5ba8c150e1fcb7a30a9793bca5b3b9b1cfd41c53 100644 (file)
@@ -138,10 +138,8 @@ pub fn intersect(&mut self, other: &IdxSet<T>) -> bool {
         bitwise(self.words_mut(), other.words(), &Intersect)
     }
 
-    pub fn iter(&self) -> Iter<T> {
-        Iter {
-            iter: self.0.iter()
-        }
+    pub fn iter(&self) -> BitIter<T> {
+        self.0.iter()
     }
 }
 
@@ -157,18 +155,6 @@ fn subtract_from(&self, other: &mut IdxSet<T>) -> bool {
     }
 }
 
-pub struct Iter<'a, T: Idx> {
-    iter: BitIter<'a, T>
-}
-
-impl<'a, T: Idx> Iterator for Iter<'a, T> {
-    type Item = T;
-
-    fn next(&mut self) -> Option<T> {
-        self.iter.next()
-    }
-}
-
 const SPARSE_MAX: usize = 8;
 
 /// A sparse index set with a maximum of SPARSE_MAX elements. Used by
@@ -221,10 +207,8 @@ fn to_dense(&self, domain_size: usize) -> IdxSet<T> {
         dense
     }
 
-    fn iter(&self) -> SparseIter<T> {
-        SparseIter {
-            iter: self.0.iter(),
-        }
+    fn iter(&self) -> slice::Iter<T> {
+        self.0.iter()
     }
 }
 
@@ -248,18 +232,6 @@ fn subtract_from(&self, other: &mut IdxSet<T>) -> bool {
     }
 }
 
-pub struct SparseIter<'a, T: Idx> {
-    iter: slice::Iter<'a, T>,
-}
-
-impl<'a, T: Idx> Iterator for SparseIter<'a, T> {
-    type Item = T;
-
-    fn next(&mut self) -> Option<T> {
-        self.iter.next().map(|e| *e)
-    }
-}
-
 /// Like IdxSet, but with a hybrid representation: sparse when there are few
 /// elements in the set, but dense when there are many. It's especially
 /// efficient for sets that typically have a small number of elements, but a
@@ -370,8 +342,8 @@ fn subtract_from(&self, other: &mut IdxSet<T>) -> bool {
 }
 
 pub enum HybridIter<'a, T: Idx> {
-    Sparse(SparseIter<'a, T>),
-    Dense(Iter<'a, T>),
+    Sparse(slice::Iter<'a, T>),
+    Dense(BitIter<'a, T>),
 }
 
 impl<'a, T: Idx> Iterator for HybridIter<'a, T> {
@@ -379,7 +351,7 @@ impl<'a, T: Idx> Iterator for HybridIter<'a, T> {
 
     fn next(&mut self) -> Option<T> {
         match self {
-            HybridIter::Sparse(sparse) => sparse.next(),
+            HybridIter::Sparse(sparse) => sparse.next().map(|e| *e),
             HybridIter::Dense(dense) => dense.next(),
         }
     }
index 6b964fec74fdd1417b1145de05f44ed2df3b696e..a4900ab57f58861d37043996794cd322e66e2b0d 100644 (file)
@@ -15,7 +15,7 @@
 
 use rustc::mir::{BasicBlock, Location};
 use rustc::ty::RegionVid;
-use rustc_data_structures::indexed_set::Iter;
+use rustc_data_structures::bitvec::BitIter;
 
 use borrow_check::location::LocationIndex;
 
@@ -67,7 +67,7 @@ impl<'b, 'gcx, 'tcx> Flows<'b, 'gcx, 'tcx> {
         }
     }
 
-    crate fn with_outgoing_borrows(&self, op: impl FnOnce(Iter<BorrowIndex>)) {
+    crate fn with_outgoing_borrows(&self, op: impl FnOnce(BitIter<BorrowIndex>)) {
         self.borrows.with_iter_outgoing(op)
     }
 }
index 1dc91cd05b33e9c7aeef0457942904c43ea47117..39643af77a17845306d25780004dabddb36221f8 100644 (file)
@@ -12,7 +12,8 @@
 //! locations.
 
 use rustc::mir::{BasicBlock, Location};
-use rustc_data_structures::indexed_set::{HybridIdxSet, IdxSet, Iter};
+use rustc_data_structures::bitvec::BitIter;
+use rustc_data_structures::indexed_set::{HybridIdxSet, IdxSet};
 
 use dataflow::{BitDenotation, BlockSets, DataflowResults};
 use dataflow::move_paths::{HasMoveData, MovePathIndex};
@@ -125,7 +126,7 @@ pub fn contains(&self, x: &BD::Idx) -> bool {
     }
 
     /// Returns an iterator over the elements present in the current state.
-    pub fn iter_incoming(&self) -> iter::Peekable<Iter<BD::Idx>> {
+    pub fn iter_incoming(&self) -> iter::Peekable<BitIter<BD::Idx>> {
         self.curr_state.iter().peekable()
     }
 
@@ -134,7 +135,7 @@ pub fn iter_incoming(&self) -> iter::Peekable<Iter<BD::Idx>> {
     /// Invokes `f` with an iterator over the resulting state.
     pub fn with_iter_outgoing<F>(&self, f: F)
     where
-        F: FnOnce(Iter<BD::Idx>),
+        F: FnOnce(BitIter<BD::Idx>),
     {
         let mut curr_state = self.curr_state.clone();
         curr_state.union(&self.stmt_gen);