Skip to content

Commit 6cfe2aa

Browse files
authored
refactor: Use ThinVec for MemoTable, halving its size (#770)
1 parent e34722a commit 6cfe2aa

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

Diff for: Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ rayon = { version = "1.10.0", optional = true }
2929

3030
# Stuff we want Update impls for by default
3131
compact_str = { version = "0.8", optional = true }
32+
thin-vec = "0.2.13"
3233

3334
[features]
3435
default = ["salsa_unstable", "rayon", "macros"]

Diff for: src/table/memo.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use std::{
55
};
66

77
use parking_lot::RwLock;
8+
use thin_vec::ThinVec;
89

910
use crate::{zalsa::MemoIngredientIndex, zalsa_local::QueryOrigin};
1011

@@ -13,7 +14,7 @@ use crate::{zalsa::MemoIngredientIndex, zalsa_local::QueryOrigin};
1314
/// and memo tables are attached to those salsa structs as auxiliary data.
1415
#[derive(Default)]
1516
pub(crate) struct MemoTable {
16-
memos: RwLock<Vec<MemoEntry>>,
17+
memos: RwLock<ThinVec<MemoEntry>>,
1718
}
1819

1920
pub(crate) trait Memo: Any + Send + Sync {
@@ -131,8 +132,8 @@ impl MemoTable {
131132
) -> Option<NonNull<M>> {
132133
let mut memos = self.memos.write();
133134
let memo_ingredient_index = memo_ingredient_index.as_usize();
134-
if memos.len() < memo_ingredient_index + 1 {
135-
memos.resize_with(memo_ingredient_index + 1, MemoEntry::default);
135+
while memos.len() < memo_ingredient_index + 1 {
136+
memos.push(MemoEntry { data: None });
136137
}
137138
let old_entry = memos[memo_ingredient_index].data.replace(MemoEntryData {
138139
type_id: TypeId::of::<M>(),

0 commit comments

Comments
 (0)