diff options
| author | Yuki Okushi <yuki.okushi@huawei.com> | 2021-06-22 06:27:22 +0900 |
|---|---|---|
| committer | Yuki Okushi <yuki.okushi@huawei.com> | 2021-07-23 18:04:28 +0900 |
| commit | 8d00be99802ff09ac5b0375b1b3a6bebf6c36b27 (patch) | |
| tree | 6916653d6a6f161e6d0291aa5b5cdeb6953e0575 /compiler | |
| parent | cb3b3cf6abcd29f408b28cf3d59489a22ccc8897 (diff) | |
| download | rust-8d00be99802ff09ac5b0375b1b3a6bebf6c36b27.tar.gz rust-8d00be99802ff09ac5b0375b1b3a6bebf6c36b27.zip | |
Use `map_while` instead of `take_while` + `map`
Diffstat (limited to 'compiler')
| -rw-r--r-- | compiler/rustc_data_structures/src/lib.rs | 2 | ||||
| -rw-r--r-- | compiler/rustc_data_structures/src/sorted_map/index_map.rs | 8 |
2 files changed, 6 insertions, 4 deletions
diff --git a/compiler/rustc_data_structures/src/lib.rs b/compiler/rustc_data_structures/src/lib.rs index 4467980054f..376513d3586 100644 --- a/compiler/rustc_data_structures/src/lib.rs +++ b/compiler/rustc_data_structures/src/lib.rs @@ -27,6 +27,8 @@ #![feature(min_type_alias_impl_trait)] #![allow(rustc::default_hash_types)] #![deny(unaligned_references)] +#![feature(iter_map_while)] +#![feature(bool_to_option)] #[macro_use] extern crate tracing; diff --git a/compiler/rustc_data_structures/src/sorted_map/index_map.rs b/compiler/rustc_data_structures/src/sorted_map/index_map.rs index 2054f5eebf5..e92db9ea128 100644 --- a/compiler/rustc_data_structures/src/sorted_map/index_map.rs +++ b/compiler/rustc_data_structures/src/sorted_map/index_map.rs @@ -86,10 +86,10 @@ impl<I: Idx, K: Ord, V> SortedIndexMultiMap<I, K, V> { /// insertion order. pub fn get_by_key_enumerated(&'a self, key: K) -> impl '_ + Iterator<Item = (I, &V)> { let lower_bound = self.idx_sorted_by_item_key.partition_point(|&i| self.items[i].0 < key); - self.idx_sorted_by_item_key[lower_bound..] - .iter() - .take_while(move |&&i| self.items[i].0.eq(&key)) - .map(move |&idx| (idx, &self.items[idx].1)) + self.idx_sorted_by_item_key[lower_bound..].iter().map_while(move |&i| { + let (k, v) = &self.items[i]; + (k == &key).then_some((i, v)) + }) } } |
