Skip to content

Commit ea99739

Browse files
authored
Replace memo queue with append-only vector (#767)
* replace memo queue with append-only vector * reuse `DeletedEntries` list across revisions
1 parent e826b5a commit ea99739

File tree

2 files changed

+11
-10
lines changed

2 files changed

+11
-10
lines changed

Diff for: src/function.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,8 @@ where
296296
self.memo_ingredient_indices.get(ingredient_index),
297297
)
298298
});
299-
std::mem::take(&mut self.deleted_entries);
299+
300+
self.deleted_entries.clear();
300301
}
301302

302303
fn fmt_index(&self, index: crate::Id, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {

Diff for: src/function/delete.rs

+9-9
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
11
use std::ptr::NonNull;
22

3-
use crossbeam_queue::SegQueue;
4-
53
use super::memo::Memo;
64
use super::Configuration;
75

86
/// Stores the list of memos that have been deleted so they can be freed
97
/// once the next revision starts. See the comment on the field
108
/// `deleted_entries` of [`FunctionIngredient`][] for more details.
119
pub(super) struct DeletedEntries<C: Configuration> {
12-
seg_queue: SegQueue<SharedBox<Memo<C::Output<'static>>>>,
10+
memos: boxcar::Vec<SharedBox<Memo<C::Output<'static>>>>,
1311
}
1412

1513
unsafe impl<T: Send> Send for SharedBox<T> {}
@@ -18,30 +16,32 @@ unsafe impl<T: Sync> Sync for SharedBox<T> {}
1816
impl<C: Configuration> Default for DeletedEntries<C> {
1917
fn default() -> Self {
2018
Self {
21-
seg_queue: Default::default(),
19+
memos: Default::default(),
2220
}
2321
}
2422
}
2523

2624
impl<C: Configuration> DeletedEntries<C> {
2725
/// # Safety
2826
///
29-
/// The memo must be valid and safe to free when the `DeletedEntries` list is dropped.
27+
/// The memo must be valid and safe to free when the `DeletedEntries` list is cleared or dropped.
3028
pub(super) unsafe fn push(&self, memo: NonNull<Memo<C::Output<'_>>>) {
3129
let memo = unsafe {
3230
std::mem::transmute::<NonNull<Memo<C::Output<'_>>>, NonNull<Memo<C::Output<'static>>>>(
3331
memo,
3432
)
3533
};
3634

37-
self.seg_queue.push(SharedBox(memo));
35+
self.memos.push(SharedBox(memo));
36+
}
37+
38+
/// Free all deleted memos, keeping the list available for reuse.
39+
pub(super) fn clear(&mut self) {
40+
self.memos.clear();
3841
}
3942
}
4043

4144
/// A wrapper around `NonNull` that frees the allocation when it is dropped.
42-
///
43-
/// `crossbeam::SegQueue` does not expose mutable accessors so we have to create
44-
/// a wrapper to run code during `Drop`.
4545
struct SharedBox<T>(NonNull<T>);
4646

4747
impl<T> Drop for SharedBox<T> {

0 commit comments

Comments
 (0)