diff --git a/Cargo.toml b/Cargo.toml index 95c8be91e..262a11206 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -29,6 +29,7 @@ rayon = { version = "1.10.0", optional = true } # Stuff we want Update impls for by default compact_str = { version = "0.8", optional = true } +thin-vec = "0.2.13" [features] default = ["salsa_unstable", "rayon", "macros"] diff --git a/src/table/memo.rs b/src/table/memo.rs index 23bca7e2a..a56c10cd5 100644 --- a/src/table/memo.rs +++ b/src/table/memo.rs @@ -5,6 +5,7 @@ use std::{ }; use parking_lot::RwLock; +use thin_vec::ThinVec; use crate::{zalsa::MemoIngredientIndex, zalsa_local::QueryOrigin}; @@ -13,7 +14,7 @@ use crate::{zalsa::MemoIngredientIndex, zalsa_local::QueryOrigin}; /// and memo tables are attached to those salsa structs as auxiliary data. #[derive(Default)] pub(crate) struct MemoTable { - memos: RwLock>, + memos: RwLock>, } pub(crate) trait Memo: Any + Send + Sync { @@ -131,8 +132,8 @@ impl MemoTable { ) -> Option> { let mut memos = self.memos.write(); let memo_ingredient_index = memo_ingredient_index.as_usize(); - if memos.len() < memo_ingredient_index + 1 { - memos.resize_with(memo_ingredient_index + 1, MemoEntry::default); + while memos.len() < memo_ingredient_index + 1 { + memos.push(MemoEntry { data: None }); } let old_entry = memos[memo_ingredient_index].data.replace(MemoEntryData { type_id: TypeId::of::(),