Skip to content

Commit dd72860

Browse files
committed
Implement the clone part of Arc::make_mut using Arc::clone_from_ref_in
1 parent ca9ec68 commit dd72860

File tree

1 file changed

+1
-13
lines changed

1 file changed

+1
-13
lines changed

library/alloc/src/sync.rs

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2504,19 +2504,7 @@ impl<T: ?Sized + CloneToUninit, A: Allocator + Clone> Arc<T, A> {
25042504
// deallocated.
25052505
if this.inner().strong.compare_exchange(1, 0, Acquire, Relaxed).is_err() {
25062506
// Another strong pointer exists, so we must clone.
2507-
2508-
let this_data_ref: &T = &**this;
2509-
// `in_progress` drops the allocation if we panic before finishing initializing it.
2510-
let mut in_progress: UniqueArcUninit<T, A> =
2511-
UniqueArcUninit::new(this_data_ref, this.alloc.clone());
2512-
2513-
let initialized_clone = unsafe {
2514-
// Clone. If the clone panics, `in_progress` will be dropped and clean up.
2515-
this_data_ref.clone_to_uninit(in_progress.data_ptr().cast());
2516-
// Cast type of pointer, now that it is initialized.
2517-
in_progress.into_arc()
2518-
};
2519-
*this = initialized_clone;
2507+
*this = Arc::clone_from_ref_in(&**this, this.alloc.clone());
25202508
} else if this.inner().weak.load(Relaxed) != 1 {
25212509
// Relaxed suffices in the above because this is fundamentally an
25222510
// optimization: we are always racing with weak pointers being

0 commit comments

Comments
 (0)