From b666d26a80d9a558a1e77177c61f5fa4f8a14392 Mon Sep 17 00:00:00 2001 From: Finomnis Date: Sun, 22 Oct 2023 15:48:09 +0200 Subject: [PATCH] Rework remote_drop_collection --- src/utils/remote_drop_collection.rs | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/src/utils/remote_drop_collection.rs b/src/utils/remote_drop_collection.rs index ca1961a..c149496 100644 --- a/src/utils/remote_drop_collection.rs +++ b/src/utils/remote_drop_collection.rs @@ -62,19 +62,23 @@ impl Drop for RemoteDrop { // Important: lock first, then read the offset. let mut data = data.lock().unwrap(); - self.offset.upgrade().map(|offset| { - let offset = offset.load(Ordering::Acquire); + let offset = self + .offset + .upgrade() + .expect("Trying to delete non-existent item! Please report this.") + .load(Ordering::Acquire); - data.pop().map(|last_item| { - if offset != data.len() { - // There must have been at least two items, and we are not at the end. - // So swap first before dropping. + let last_item = data + .pop() + .expect("Trying to delete non-existent item! Please report this."); - last_item.offset.store(offset, Ordering::Release); - data[offset] = last_item; - } - }); - }); + if offset != data.len() { + // There must have been at least two items, and we are not at the end. + // So swap first before dropping. + + last_item.offset.store(offset, Ordering::Release); + data[offset] = last_item; + } } } }