From: Nicholas Nethercote Date: Thu, 13 Sep 2018 22:06:52 +0000 (+1000) Subject: Remove `Iter` and `SparseIter` in indexed_set.rs. X-Git-Url: https://git.lizzy.rs/?a=commitdiff_plain;h=56be2afec56c6c958b3185a4ce8307d13fb8bf2f;p=rust.git Remove `Iter` and `SparseIter` in indexed_set.rs. Because they're just thin wrappers around `BitIter` and `slice::Iter`. --- diff --git a/src/librustc_data_structures/indexed_set.rs b/src/librustc_data_structures/indexed_set.rs index be519e7bbde..5ba8c150e1f 100644 --- a/src/librustc_data_structures/indexed_set.rs +++ b/src/librustc_data_structures/indexed_set.rs @@ -138,10 +138,8 @@ pub fn intersect(&mut self, other: &IdxSet) -> bool { bitwise(self.words_mut(), other.words(), &Intersect) } - pub fn iter(&self) -> Iter { - Iter { - iter: self.0.iter() - } + pub fn iter(&self) -> BitIter { + self.0.iter() } } @@ -157,18 +155,6 @@ fn subtract_from(&self, other: &mut IdxSet) -> 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 { - 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 { dense } - fn iter(&self) -> SparseIter { - SparseIter { - iter: self.0.iter(), - } + fn iter(&self) -> slice::Iter { + self.0.iter() } } @@ -248,18 +232,6 @@ fn subtract_from(&self, other: &mut IdxSet) -> 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 { - 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) -> 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 { match self { - HybridIter::Sparse(sparse) => sparse.next(), + HybridIter::Sparse(sparse) => sparse.next().map(|e| *e), HybridIter::Dense(dense) => dense.next(), } } diff --git a/src/librustc_mir/borrow_check/flows.rs b/src/librustc_mir/borrow_check/flows.rs index 6b964fec74f..a4900ab57f5 100644 --- a/src/librustc_mir/borrow_check/flows.rs +++ b/src/librustc_mir/borrow_check/flows.rs @@ -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)) { + crate fn with_outgoing_borrows(&self, op: impl FnOnce(BitIter)) { self.borrows.with_iter_outgoing(op) } } diff --git a/src/librustc_mir/dataflow/at_location.rs b/src/librustc_mir/dataflow/at_location.rs index 1dc91cd05b3..39643af77a1 100644 --- a/src/librustc_mir/dataflow/at_location.rs +++ b/src/librustc_mir/dataflow/at_location.rs @@ -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> { + pub fn iter_incoming(&self) -> iter::Peekable> { self.curr_state.iter().peekable() } @@ -134,7 +135,7 @@ pub fn iter_incoming(&self) -> iter::Peekable> { /// Invokes `f` with an iterator over the resulting state. pub fn with_iter_outgoing(&self, f: F) where - F: FnOnce(Iter), + F: FnOnce(BitIter), { let mut curr_state = self.curr_state.clone(); curr_state.union(&self.stmt_gen);