diff options
| author | Nicholas Nethercote <nnethercote@mozilla.com> | 2018-09-17 13:52:35 +1000 |
|---|---|---|
| committer | Nicholas Nethercote <nnethercote@mozilla.com> | 2018-09-18 07:08:18 +1000 |
| commit | a0da3e9f4fff6aae71f56ce3452b0e38f30de5c4 (patch) | |
| tree | d70fbfe3149de2a91c9fcc33c9d69e9f5a0557e6 /src/librustc_data_structures | |
| parent | 266e2d3d69f61692a4080ff345d05c49d9f3c855 (diff) | |
Eliminate `BitwiseOperator`.
`BitwiseOperator` is an unnecessarily low-level thing. This commit replaces it with `BitSetOperator`, which works on `BitSet`s instead of words. Within `bit_set.rs`, the commit eliminates `Intersect`, `Union`, and `Subtract` by instead passing a function to `bitwise()`.
Diffstat (limited to 'src/librustc_data_structures')
| -rw-r--r-- | src/librustc_data_structures/bit_set.rs | 35 |
1 files changed, 9 insertions, 26 deletions
diff --git a/src/librustc_data_structures/bit_set.rs b/src/librustc_data_structures/bit_set.rs index 71cd4ba37ab..74f08205958 100644 --- a/src/librustc_data_structures/bit_set.rs +++ b/src/librustc_data_structures/bit_set.rs @@ -162,7 +162,7 @@ impl<T: Idx> BitSet<T> { /// Set `self = self & other` and return true if `self` changed. /// (i.e., if any bits were removed). pub fn intersect(&mut self, other: &BitSet<T>) -> bool { - bitwise(self.words_mut(), other.words(), &Intersect) + bitwise(self.words_mut(), other.words(), |a, b| { a & b }) } /// Get a slice of the underlying words. @@ -243,13 +243,13 @@ pub trait SubtractFromBitSet<T: Idx> { impl<T: Idx> UnionIntoBitSet<T> for BitSet<T> { fn union_into(&self, other: &mut BitSet<T>) -> bool { - bitwise(other.words_mut(), self.words(), &Union) + bitwise(other.words_mut(), self.words(), |a, b| { a | b }) } } impl<T: Idx> SubtractFromBitSet<T> for BitSet<T> { fn subtract_from(&self, other: &mut BitSet<T>) -> bool { - bitwise(other.words_mut(), self.words(), &Subtract) + bitwise(other.words_mut(), self.words(), |a, b| { a & !b }) } } @@ -302,43 +302,26 @@ impl<'a, T: Idx> Iterator for BitIter<'a, T> { } } -pub trait BitwiseOperator { - /// Applies some bit-operation pointwise to each of the bits in the two inputs. - fn join(&self, pred1: Word, pred2: Word) -> Word; +pub trait BitSetOperator { + /// Combine one bitset into another. + fn join<T: Idx>(&self, inout_set: &mut BitSet<T>, in_set: &BitSet<T>) -> bool; } #[inline] -pub fn bitwise<Op: BitwiseOperator>(out_vec: &mut [Word], in_vec: &[Word], op: &Op) -> bool +fn bitwise<Op>(out_vec: &mut [Word], in_vec: &[Word], op: Op) -> bool + where Op: Fn(Word, Word) -> Word { assert_eq!(out_vec.len(), in_vec.len()); let mut changed = false; for (out_elem, in_elem) in out_vec.iter_mut().zip(in_vec.iter()) { let old_val = *out_elem; - let new_val = op.join(old_val, *in_elem); + let new_val = op(old_val, *in_elem); *out_elem = new_val; changed |= old_val != new_val; } changed } -pub struct Intersect; -impl BitwiseOperator for Intersect { - #[inline] - fn join(&self, a: Word, b: Word) -> Word { a & b } -} - -pub struct Union; -impl BitwiseOperator for Union { - #[inline] - fn join(&self, a: Word, b: Word) -> Word { a | b } -} - -pub struct Subtract; -impl BitwiseOperator for Subtract { - #[inline] - fn join(&self, a: Word, b: Word) -> Word { a & !b } -} - const SPARSE_MAX: usize = 8; /// A fixed-size bitset type with a sparse representation and a maximum of |
