From 8d00be99802ff09ac5b0375b1b3a6bebf6c36b27 Mon Sep 17 00:00:00 2001 From: Yuki Okushi Date: Tue, 22 Jun 2021 06:27:22 +0900 Subject: [PATCH] Use `map_while` instead of `take_while` + `map` --- compiler/rustc_data_structures/src/lib.rs | 2 ++ .../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 @@ pub fn get_by_key(&'a self, key: K) -> impl 'a + Iterator { /// insertion order. pub fn get_by_key_enumerated(&'a self, key: K) -> impl '_ + Iterator { 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)) + }) } }