Use FastIndexSet for UniqueArena.

This commit is contained in:
Jim Blandy
2023-09-20 15:25:47 -07:00
parent b586631efe
commit 9105036be7
2 changed files with 8 additions and 9 deletions

View File

@@ -5,8 +5,7 @@ use std::{cmp::Ordering, fmt, hash, marker::PhantomData, num::NonZeroU32, ops};
/// the same size and representation as `Handle<T>`.
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<T> {
set: IndexSet<T>,
set: FastIndexSet<T>,
/// 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<T> UniqueArena<T> {
/// 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();

View File

@@ -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<T> 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<T> 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() {