Skip to content

Commit

Permalink
Remove Iter and SparseIter in indexed_set.rs.
Browse files Browse the repository at this point in the history
Because they're just thin wrappers around `BitIter` and `slice::Iter`.
  • Loading branch information
nnethercote committed Sep 13, 2018
1 parent b697409 commit 56be2af
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 40 deletions.
42 changes: 7 additions & 35 deletions src/librustc_data_structures/indexed_set.rs
Expand Up @@ -138,10 +138,8 @@ impl<T: Idx> IdxSet<T> {
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()
}
}

Expand All @@ -157,18 +155,6 @@ impl<T: Idx> SubtractFromIdxSet<T> for IdxSet<T> {
}
}

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
Expand Down Expand Up @@ -221,10 +207,8 @@ impl<T: Idx> SparseIdxSet<T> {
dense
}

fn iter(&self) -> SparseIter<T> {
SparseIter {
iter: self.0.iter(),
}
fn iter(&self) -> slice::Iter<T> {
self.0.iter()
}
}

Expand All @@ -248,18 +232,6 @@ impl<T: Idx> SubtractFromIdxSet<T> for SparseIdxSet<T> {
}
}

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
Expand Down Expand Up @@ -370,16 +342,16 @@ impl<T: Idx> SubtractFromIdxSet<T> for HybridIdxSet<T> {
}

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> {
type Item = 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(),
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_mir/borrow_check/flows.rs
Expand Up @@ -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;

Expand Down Expand Up @@ -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)
}
}
Expand Down
7 changes: 4 additions & 3 deletions src/librustc_mir/dataflow/at_location.rs
Expand Up @@ -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};
Expand Down Expand Up @@ -125,7 +126,7 @@ where
}

/// 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()
}

Expand All @@ -134,7 +135,7 @@ where
/// 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);
Expand Down

0 comments on commit 56be2af

Please sign in to comment.