Skip to content

Commit 8d00be9

Browse files
committed
Use map_while instead of take_while + map
1 parent cb3b3cf commit 8d00be9

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

compiler/rustc_data_structures/src/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
#![feature(min_type_alias_impl_trait)]
2828
#![allow(rustc::default_hash_types)]
2929
#![deny(unaligned_references)]
30+
#![feature(iter_map_while)]
31+
#![feature(bool_to_option)]
3032

3133
#[macro_use]
3234
extern crate tracing;

compiler/rustc_data_structures/src/sorted_map/index_map.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -86,10 +86,10 @@ impl<I: Idx, K: Ord, V> SortedIndexMultiMap<I, K, V> {
8686
/// insertion order.
8787
pub fn get_by_key_enumerated(&'a self, key: K) -> impl '_ + Iterator<Item = (I, &V)> {
8888
let lower_bound = self.idx_sorted_by_item_key.partition_point(|&i| self.items[i].0 < key);
89-
self.idx_sorted_by_item_key[lower_bound..]
90-
.iter()
91-
.take_while(move |&&i| self.items[i].0.eq(&key))
92-
.map(move |&idx| (idx, &self.items[idx].1))
89+
self.idx_sorted_by_item_key[lower_bound..].iter().map_while(move |&i| {
90+
let (k, v) = &self.items[i];
91+
(k == &key).then_some((i, v))
92+
})
9393
}
9494
}
9595

0 commit comments

Comments
 (0)