diff --git a/src/function.rs b/src/function.rs index 24fa505c0..38338820e 100644 --- a/src/function.rs +++ b/src/function.rs @@ -296,7 +296,8 @@ where self.memo_ingredient_indices.get(ingredient_index), ) }); - std::mem::take(&mut self.deleted_entries); + + self.deleted_entries.clear(); } fn fmt_index(&self, index: crate::Id, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { diff --git a/src/function/delete.rs b/src/function/delete.rs index ce09b298e..8206dd2f0 100644 --- a/src/function/delete.rs +++ b/src/function/delete.rs @@ -1,7 +1,5 @@ use std::ptr::NonNull; -use crossbeam_queue::SegQueue; - use super::memo::Memo; use super::Configuration; @@ -9,7 +7,7 @@ use super::Configuration; /// once the next revision starts. See the comment on the field /// `deleted_entries` of [`FunctionIngredient`][] for more details. pub(super) struct DeletedEntries { - seg_queue: SegQueue>>>, + memos: boxcar::Vec>>>, } unsafe impl Send for SharedBox {} @@ -18,7 +16,7 @@ unsafe impl Sync for SharedBox {} impl Default for DeletedEntries { fn default() -> Self { Self { - seg_queue: Default::default(), + memos: Default::default(), } } } @@ -26,7 +24,7 @@ impl Default for DeletedEntries { impl DeletedEntries { /// # Safety /// - /// The memo must be valid and safe to free when the `DeletedEntries` list is dropped. + /// The memo must be valid and safe to free when the `DeletedEntries` list is cleared or dropped. pub(super) unsafe fn push(&self, memo: NonNull>>) { let memo = unsafe { std::mem::transmute::>>, NonNull>>>( @@ -34,14 +32,16 @@ impl DeletedEntries { ) }; - self.seg_queue.push(SharedBox(memo)); + self.memos.push(SharedBox(memo)); + } + + /// Free all deleted memos, keeping the list available for reuse. + pub(super) fn clear(&mut self) { + self.memos.clear(); } } /// A wrapper around `NonNull` that frees the allocation when it is dropped. -/// -/// `crossbeam::SegQueue` does not expose mutable accessors so we have to create -/// a wrapper to run code during `Drop`. struct SharedBox(NonNull); impl Drop for SharedBox {