Use UnordSet instead of FxHashSet for names_imported_by_glob_use query.

This commit is contained in:
Michael Woerister 2023-02-21 15:18:10 +01:00
parent ee8bc5b0b2
commit 422208ae52
6 changed files with 42 additions and 12 deletions

View file

@ -109,6 +109,12 @@ impl<T, I: Iterator<Item = T>> UnordItems<T, I> {
}
}
impl<T> UnordItems<T, std::iter::Empty<T>> {
pub fn empty() -> Self {
UnordItems(std::iter::empty())
}
}
impl<'a, T: Clone + 'a, I: Iterator<Item = &'a T>> UnordItems<&'a T, I> {
#[inline]
pub fn cloned(self) -> UnordItems<T, impl Iterator<Item = T>> {
@ -133,6 +139,20 @@ impl<T: Ord, I: Iterator<Item = T>> UnordItems<T, I> {
items
}
#[inline]
pub fn into_sorted_stable_ord(self, use_stable_sort: bool) -> Vec<T>
where
T: Ord + StableOrd,
{
let mut items: Vec<T> = self.0.collect();
if use_stable_sort {
items.sort();
} else {
items.sort_unstable()
}
items
}
pub fn into_sorted_small_vec<HCX, const LEN: usize>(self, hcx: &HCX) -> SmallVec<[T; LEN]>
where
T: ToStableHashKey<HCX>,
@ -175,6 +195,11 @@ impl<V: Eq + Hash> UnordSet<V> {
self.inner.len()
}
#[inline]
pub fn is_empty(&self) -> bool {
self.inner.is_empty()
}
#[inline]
pub fn insert(&mut self, v: V) -> bool {
self.inner.insert(v)
@ -253,7 +278,7 @@ impl<V: Eq + Hash> UnordSet<V> {
// We can safely extend this UnordSet from a set of unordered values because that
// won't expose the internal ordering anywhere.
#[inline]
pub fn extend<I: Iterator<Item = V>>(&mut self, items: UnordItems<V, I>) {
pub fn extend_unord<I: Iterator<Item = V>>(&mut self, items: UnordItems<V, I>) {
self.inner.extend(items.0)
}
@ -277,6 +302,12 @@ impl<V: Hash + Eq> FromIterator<V> for UnordSet<V> {
}
}
impl<V: Hash + Eq> From<FxHashSet<V>> for UnordSet<V> {
fn from(value: FxHashSet<V>) -> Self {
UnordSet { inner: value }
}
}
impl<HCX, V: Hash + Eq + HashStable<HCX>> HashStable<HCX> for UnordSet<V> {
#[inline]
fn hash_stable(&self, hcx: &mut HCX, hasher: &mut StableHasher) {