From 8a1de57a4aaf4ff13d20fdbc162064f237bb7679 Mon Sep 17 00:00:00 2001 From: Michael Woerister Date: Fri, 2 Dec 2022 16:27:25 +0100 Subject: Use UnordSet instead of FxHashSet in define_id_collections!(). --- compiler/rustc_data_structures/src/fx.rs | 2 +- compiler/rustc_data_structures/src/unord.rs | 26 +++++++++++++++++++++++--- 2 files changed, 24 insertions(+), 4 deletions(-) (limited to 'compiler/rustc_data_structures/src') diff --git a/compiler/rustc_data_structures/src/fx.rs b/compiler/rustc_data_structures/src/fx.rs index 0d0c51b6819..11f9def34aa 100644 --- a/compiler/rustc_data_structures/src/fx.rs +++ b/compiler/rustc_data_structures/src/fx.rs @@ -12,7 +12,7 @@ pub type IndexEntry<'a, K, V> = indexmap::map::Entry<'a, K, V>; macro_rules! define_id_collections { ($map_name:ident, $set_name:ident, $entry_name:ident, $key:ty) => { pub type $map_name = $crate::fx::FxHashMap<$key, T>; - pub type $set_name = $crate::fx::FxHashSet<$key>; + pub type $set_name = $crate::unord::UnordSet<$key>; pub type $entry_name<'a, T> = $crate::fx::StdEntry<'a, $key, T>; }; } diff --git a/compiler/rustc_data_structures/src/unord.rs b/compiler/rustc_data_structures/src/unord.rs index 14257e4d5c6..cfd7ee097a3 100644 --- a/compiler/rustc_data_structures/src/unord.rs +++ b/compiler/rustc_data_structures/src/unord.rs @@ -38,17 +38,17 @@ impl> UnordItems { } #[inline] - pub fn all bool>(mut self, f: F) -> bool { + pub fn all bool>(mut self, f: F) -> bool { self.0.all(f) } #[inline] - pub fn any bool>(mut self, f: F) -> bool { + pub fn any bool>(mut self, f: F) -> bool { self.0.any(f) } #[inline] - pub fn filter bool>(self, f: F) -> UnordItems> { + pub fn filter bool>(self, f: F) -> UnordItems> { UnordItems(self.0.filter(f)) } @@ -96,6 +96,15 @@ impl> UnordItems { pub fn count(self) -> usize { self.0.count() } + + #[inline] + pub fn flat_map(self, f: F) -> UnordItems> + where + U: IntoIterator, + F: Fn(T) -> U, + { + UnordItems(self.0.flat_map(f)) + } } impl<'a, T: Clone + 'a, I: Iterator> UnordItems<&'a T, I> { @@ -193,6 +202,11 @@ impl UnordSet { pub fn extend>(&mut self, items: UnordItems) { self.inner.extend(items.0) } + + #[inline] + pub fn clear(&mut self) { + self.inner.clear(); + } } impl Extend for UnordSet { @@ -201,6 +215,12 @@ impl Extend for UnordSet { } } +impl FromIterator for UnordSet { + fn from_iter>(iter: T) -> Self { + UnordSet { inner: FxHashSet::from_iter(iter) } + } +} + impl> HashStable for UnordSet { #[inline] fn hash_stable(&self, hcx: &mut HCX, hasher: &mut StableHasher) { -- cgit 1.4.1-3-g733a5