diff options
Diffstat (limited to 'compiler/rustc_index/src')
| -rw-r--r-- | compiler/rustc_index/src/bit_set.rs | 9 | ||||
| -rw-r--r-- | compiler/rustc_index/src/vec.rs | 23 |
2 files changed, 18 insertions, 14 deletions
diff --git a/compiler/rustc_index/src/bit_set.rs b/compiler/rustc_index/src/bit_set.rs index 1995fd64e6f..67b3cec0a3e 100644 --- a/compiler/rustc_index/src/bit_set.rs +++ b/compiler/rustc_index/src/bit_set.rs @@ -841,7 +841,7 @@ impl<T: Idx> GrowableBitSet<T> { #[inline] pub fn contains(&self, elem: T) -> bool { let (word_index, mask) = word_index_and_mask(elem); - if let Some(word) = self.bit_set.words.get(word_index) { (word & mask) != 0 } else { false } + self.bit_set.words.get(word_index).map_or(false, |word| (word & mask) != 0) } } @@ -990,8 +990,9 @@ impl<R: Idx, C: Idx> BitMatrix<R, C> { pub fn insert_all_into_row(&mut self, row: R) { assert!(row.index() < self.num_rows); let (start, end) = self.range(row); - for word in self.words[start..end].iter_mut() { - *word = !0; + let words = &mut self.words[..]; + for index in start..end { + words[index] = !0; } self.clear_excess_bits(row); } @@ -1143,7 +1144,7 @@ impl<R: Idx, C: Idx> SparseBitMatrix<R, C> { /// Iterates through all the columns set to true in a given row of /// the matrix. - pub fn iter(&self, row: R) -> impl Iterator<Item = C> + '_ { + pub fn iter<'a>(&'a self, row: R) -> impl Iterator<Item = C> + 'a { self.row(row).into_iter().flat_map(|r| r.iter()) } diff --git a/compiler/rustc_index/src/vec.rs b/compiler/rustc_index/src/vec.rs index e9efa2f255d..45639bad243 100644 --- a/compiler/rustc_index/src/vec.rs +++ b/compiler/rustc_index/src/vec.rs @@ -124,10 +124,7 @@ macro_rules! newtype_index { #[inline] $v const fn from_usize(value: usize) -> Self { - #[cfg(not(bootstrap))] assert!(value <= ($max as usize)); - #[cfg(bootstrap)] - [()][(value > ($max as usize)) as usize]; unsafe { Self::from_u32_unchecked(value as u32) } @@ -135,10 +132,7 @@ macro_rules! newtype_index { #[inline] $v const fn from_u32(value: u32) -> Self { - #[cfg(not(bootstrap))] assert!(value <= $max); - #[cfg(bootstrap)] - [()][(value > $max) as usize]; unsafe { Self::from_u32_unchecked(value) } @@ -634,15 +628,18 @@ impl<I: Idx, T> IndexVec<I, T> { } #[inline] - pub fn drain<R: RangeBounds<usize>>(&mut self, range: R) -> impl Iterator<Item = T> + '_ { + pub fn drain<'a, R: RangeBounds<usize>>( + &'a mut self, + range: R, + ) -> impl Iterator<Item = T> + 'a { self.raw.drain(range) } #[inline] - pub fn drain_enumerated<R: RangeBounds<usize>>( - &mut self, + pub fn drain_enumerated<'a, R: RangeBounds<usize>>( + &'a mut self, range: R, - ) -> impl Iterator<Item = (I, T)> + '_ { + ) -> impl Iterator<Item = (I, T)> + 'a { self.raw.drain(range).enumerate().map(|(n, t)| (I::new(n), t)) } @@ -738,6 +735,12 @@ impl<I: Idx, T> IndexVec<I, Option<T>> { self.ensure_contains_elem(index, || None); self[index].get_or_insert_with(value) } + + #[inline] + pub fn remove(&mut self, index: I) -> Option<T> { + self.ensure_contains_elem(index, || None); + self[index].take() + } } impl<I: Idx, T: Clone> IndexVec<I, T> { |
