|
12 | 12 | // See the License for the specific language governing permissions and |
13 | 13 | // limitations under the License. |
14 | 14 |
|
15 | | -use std::{ |
16 | | - collections::VecDeque, |
17 | | - future::Future, |
18 | | - mem::{self, ManuallyDrop}, |
19 | | - sync::Arc, |
20 | | -}; |
| 15 | +use std::{collections::VecDeque, future::Future, sync::Arc}; |
21 | 16 |
|
22 | 17 | use eyeball_im::{ObservableVector, ObservableVectorTransaction, ObservableVectorTransactionEntry}; |
23 | 18 | use indexmap::IndexMap; |
@@ -403,19 +398,21 @@ impl TimelineInnerState { |
403 | 398 | } |
404 | 399 |
|
405 | 400 | fn transaction(&mut self) -> TimelineInnerStateTransaction<'_> { |
406 | | - let items = ManuallyDrop::new(self.items.transaction()); |
407 | | - let meta = ManuallyDrop::new(self.meta.clone()); |
| 401 | + let items = self.items.transaction(); |
| 402 | + let meta = self.meta.clone(); |
408 | 403 | TimelineInnerStateTransaction { items, previous_meta: &mut self.meta, meta } |
409 | 404 | } |
410 | 405 | } |
411 | 406 |
|
412 | 407 | pub(in crate::timeline) struct TimelineInnerStateTransaction<'a> { |
413 | | - pub items: ManuallyDrop<ObservableVectorTransaction<'a, Arc<TimelineItem>>>, |
| 408 | + /// A vector transaction over the items themselves. Holds temporary state |
| 409 | + /// until committed. |
| 410 | + pub items: ObservableVectorTransaction<'a, Arc<TimelineItem>>, |
414 | 411 |
|
415 | 412 | /// A clone of the previous meta, that we're operating on during the |
416 | 413 | /// transaction, and that will be committed to the previous meta location in |
417 | 414 | /// [`Self::commit`]. |
418 | | - pub meta: ManuallyDrop<TimelineInnerMetadata>, |
| 415 | + pub meta: TimelineInnerMetadata, |
419 | 416 |
|
420 | 417 | /// Pointer to the previous meta, only used during [`Self::commit`]. |
421 | 418 | previous_meta: &'a mut TimelineInnerMetadata, |
@@ -624,19 +621,11 @@ impl TimelineInnerStateTransaction<'_> { |
624 | 621 | self.meta.update_read_marker(&mut self.items); |
625 | 622 | } |
626 | 623 |
|
627 | | - fn commit(mut self) { |
628 | | - let Self { items, previous_meta, meta } = &mut self; |
629 | | - |
630 | | - // Safety: self is forgotten to avoid double free from drop. |
631 | | - let meta = unsafe { ManuallyDrop::take(meta) }; |
| 624 | + fn commit(self) { |
| 625 | + let Self { items, previous_meta, meta } = self; |
632 | 626 |
|
633 | 627 | // Replace the pointer to the previous meta with the new one. |
634 | | - **previous_meta = meta; |
635 | | - |
636 | | - // Safety: self is forgotten to avoid double free from drop. |
637 | | - let items = unsafe { ManuallyDrop::take(items) }; |
638 | | - |
639 | | - mem::forget(self); |
| 628 | + *previous_meta = meta; |
640 | 629 |
|
641 | 630 | items.commit(); |
642 | 631 | } |
@@ -688,17 +677,6 @@ impl TimelineInnerStateTransaction<'_> { |
688 | 677 | } |
689 | 678 | } |
690 | 679 |
|
691 | | -impl Drop for TimelineInnerStateTransaction<'_> { |
692 | | - fn drop(&mut self) { |
693 | | - warn!("timeline state transaction cancelled"); |
694 | | - // Safety: self.items is not touched anymore, the only other place |
695 | | - // dropping is Self::commit which makes sure to skip this Drop impl. |
696 | | - unsafe { |
697 | | - ManuallyDrop::drop(&mut self.items); |
698 | | - } |
699 | | - } |
700 | | -} |
701 | | - |
702 | 680 | #[derive(Clone, Debug)] |
703 | 681 | pub(in crate::timeline) struct TimelineInnerMetadata { |
704 | 682 | /// List of all the events as received in the timeline, even the ones that |
|
0 commit comments