Skip to content

Commit dcdf1ec

Browse files
Rollup merge of #153094 - cuviper:AppendOnlyVec-iters, r=Kivooeo
Simplify `AppendOnlyVec` iterators This isn't a big deal, but I noticed that these iterators were more complicated than they need to be.
2 parents 58ab407 + 696a7a1 commit dcdf1ec

1 file changed

Lines changed: 3 additions & 6 deletions

File tree

  • compiler/rustc_data_structures/src/sync

compiler/rustc_data_structures/src/sync/vec.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,20 +46,17 @@ impl<T: Copy> AppendOnlyVec<T> {
4646
}
4747

4848
pub fn iter_enumerated(&self) -> impl Iterator<Item = (usize, T)> {
49-
(0..)
50-
.map(|i| (i, self.get(i)))
51-
.take_while(|(_, o)| o.is_some())
52-
.filter_map(|(i, o)| Some((i, o?)))
49+
(0..).map_while(|i| Some((i, self.get(i)?)))
5350
}
5451

5552
pub fn iter(&self) -> impl Iterator<Item = T> {
56-
(0..).map(|i| self.get(i)).take_while(|o| o.is_some()).flatten()
53+
(0..).map_while(|i| self.get(i))
5754
}
5855
}
5956

6057
impl<T: Copy + PartialEq> AppendOnlyVec<T> {
6158
pub fn contains(&self, val: T) -> bool {
62-
self.iter_enumerated().any(|(_, v)| v == val)
59+
self.iter().any(|v| v == val)
6360
}
6461
}
6562

0 commit comments

Comments
 (0)