From 9105036be7f60bb9fc35eecad5248a90b2827f2c Mon Sep 17 00:00:00 2001 From: Jim Blandy Date: Wed, 20 Sep 2023 15:25:47 -0700 Subject: [PATCH] Use `FastIndexSet` for `UniqueArena`. --- src/arena.rs | 11 +++++------ src/compact/mod.rs | 6 +++--- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/src/arena.rs b/src/arena.rs index 1499cf1772..49b9328012 100644 --- a/src/arena.rs +++ b/src/arena.rs @@ -5,8 +5,7 @@ use std::{cmp::Ordering, fmt, hash, marker::PhantomData, num::NonZeroU32, ops}; /// the same size and representation as `Handle`. type Index = NonZeroU32; -use crate::Span; -use indexmap::set::IndexSet; +use crate::{FastIndexSet, Span}; #[derive(Clone, Copy, Debug, thiserror::Error, PartialEq)] #[error("Handle {index} of {kind} is either not present, or inaccessible yet")] @@ -516,11 +515,11 @@ mod tests { /// `UniqueArena` is `HashSet`-like. #[cfg_attr(feature = "clone", derive(Clone))] pub struct UniqueArena { - set: IndexSet, + set: FastIndexSet, /// Spans for the elements, indexed by handle. /// - /// The length of this vector is always equal to `set.len()`. `IndexSet` + /// The length of this vector is always equal to `set.len()`. `FastIndexSet` /// promises that its elements "are indexed in a compact range, without /// holes in the range 0..set.len()", so we can always use the indices /// returned by insertion as indices into this vector. @@ -532,7 +531,7 @@ impl UniqueArena { /// Create a new arena with no initial capacity allocated. pub fn new() -> Self { UniqueArena { - set: IndexSet::new(), + set: FastIndexSet::default(), #[cfg(feature = "span")] span_info: Vec::new(), } @@ -741,7 +740,7 @@ where where D: serde::Deserializer<'de>, { - let set = IndexSet::deserialize(deserializer)?; + let set = FastIndexSet::deserialize(deserializer)?; #[cfg(feature = "span")] let span_info = std::iter::repeat(Span::default()).take(set.len()).collect(); diff --git a/src/compact/mod.rs b/src/compact/mod.rs index e0de1fe971..137f3bbe30 100644 --- a/src/compact/mod.rs +++ b/src/compact/mod.rs @@ -95,9 +95,9 @@ pub fn compact(module: &mut crate::Module) { // Drop unused types from the type arena. // - // `IndexSet`s don't have an underlying Vec that we can steal, compact in - // place, and then rebuild the `IndexSet` from. So we have to rebuild the - // type arena from scratch. + // `FastIndexSet`s don't have an underlying Vec that we can + // steal, compact in place, and then rebuild the `FastIndexSet` + // from. So we have to rebuild the type arena from scratch. log::trace!("compacting types"); let mut new_types = arena::UniqueArena::new(); for (old_handle, mut ty, span) in module.types.drain_all() {