Skip to content

Commit

Permalink
Remove IdxSet::each_bit
Browse files Browse the repository at this point in the history
  • Loading branch information
varkor committed Mar 6, 2018
1 parent 6701d90 commit 89d1247
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 39 deletions.
33 changes: 0 additions & 33 deletions src/librustc_data_structures/indexed_set.rs
Expand Up @@ -225,12 +225,6 @@ impl<T: Idx> IdxSet<T> {
}
}

/// Calls `f` on each index value held in this set, up to the
/// bound `max_bits` on the size of universe of indexes.
pub fn each_bit<F>(&self, max_bits: usize, f: F) where F: FnMut(T) {
each_bit(self, max_bits, f)
}

pub fn elems(&self, universe_size: usize) -> Elems<T> {
Elems { i: 0, set: self, universe_size: universe_size }
}
Expand All @@ -256,33 +250,6 @@ impl<'a, T: Idx> Iterator for Elems<'a, T> {
}
}
}

fn each_bit<T: Idx, F>(words: &IdxSet<T>, max_bits: usize, mut f: F) where F: FnMut(T) {
let usize_bits: usize = mem::size_of::<usize>() * 8;

for (word_index, &word) in words.words().iter().enumerate() {
if word != 0 {
let base_index = word_index * usize_bits;
for offset in 0..usize_bits {
let bit = 1 << offset;
if (word & bit) != 0 {
// NB: we round up the total number of bits
// that we store in any given bit set so that
// it is an even multiple of usize::BITS. This
// means that there may be some stray bits at
// the end that do not correspond to any
// actual value; that's why we first check
// that we are in range of bits_per_block.
let bit_index = base_index + offset as usize;
if bit_index >= max_bits {
return;
} else {
f(Idx::new(bit_index));
}
}
}
}
}
}

pub struct Iter<'a, T: Idx> {
Expand Down
6 changes: 2 additions & 4 deletions src/librustc_mir/dataflow/at_location.rs
Expand Up @@ -81,8 +81,7 @@ where
where
F: FnMut(BD::Idx),
{
self.curr_state
.each_bit(self.base_results.operator().bits_per_block(), f)
self.curr_state.iter().for_each(f)
}

/// Iterate over each `gen` bit in the current effect (invoke
Expand All @@ -92,8 +91,7 @@ where
where
F: FnMut(BD::Idx),
{
self.stmt_gen
.each_bit(self.base_results.operator().bits_per_block(), f)
self.stmt_gen.iter().for_each(f)
}

pub fn new(results: DataflowResults<BD>) -> Self {
Expand Down
3 changes: 1 addition & 2 deletions src/librustc_mir/dataflow/mod.rs
Expand Up @@ -444,8 +444,7 @@ pub struct DataflowState<O: BitDenotation>
impl<O: BitDenotation> DataflowState<O> {
pub fn each_bit<F>(&self, words: &IdxSet<O::Idx>, f: F) where F: FnMut(O::Idx)
{
let bits_per_block = self.operator.bits_per_block();
words.each_bit(bits_per_block, f)
words.iter().for_each(f)
}

pub(crate) fn interpret_set<'c, P>(&self,
Expand Down

0 comments on commit 89d1247

Please sign in to comment.