File tree 2 files changed +5
-23
lines changed
2 files changed +5
-23
lines changed Original file line number Diff line number Diff line change @@ -1107,20 +1107,10 @@ impl<T: ?Sized> Rc<T> {
1107
1107
// `&*(ptr as *const RcBox<T>)`, but this created a misaligned
1108
1108
// reference (see #54908).
1109
1109
let layout = Layout :: new :: < RcBox < ( ) > > ( ) . extend ( value_layout) . unwrap ( ) . 0 . pad_to_align ( ) ;
1110
-
1111
- // Allocate for the layout.
1112
- let ptr = allocate ( layout) . unwrap_or_else ( |_| handle_alloc_error ( layout) ) ;
1113
-
1114
- // Initialize the RcBox
1115
- let inner = mem_to_rcbox ( ptr. as_non_null_ptr ( ) . as_ptr ( ) ) ;
1116
1110
unsafe {
1117
- debug_assert_eq ! ( Layout :: for_value( & * inner) , layout) ;
1118
-
1119
- ptr:: write ( & mut ( * inner) . strong , Cell :: new ( 1 ) ) ;
1120
- ptr:: write ( & mut ( * inner) . weak , Cell :: new ( 1 ) ) ;
1111
+ Rc :: try_allocate_for_layout ( value_layout, allocate, mem_to_rcbox)
1112
+ . unwrap_or_else ( |_| handle_alloc_error ( layout) )
1121
1113
}
1122
-
1123
- inner
1124
1114
}
1125
1115
1126
1116
/// Allocates an `RcBox<T>` with sufficient space for
@@ -1129,6 +1119,7 @@ impl<T: ?Sized> Rc<T> {
1129
1119
///
1130
1120
/// The function `mem_to_rcbox` is called with the data pointer
1131
1121
/// and must return back a (potentially fat)-pointer for the `RcBox<T>`.
1122
+ #[ inline]
1132
1123
unsafe fn try_allocate_for_layout (
1133
1124
value_layout : Layout ,
1134
1125
allocate : impl FnOnce ( Layout ) -> Result < NonNull < [ u8 ] > , AllocError > ,
Original file line number Diff line number Diff line change @@ -1085,19 +1085,10 @@ impl<T: ?Sized> Arc<T> {
1085
1085
// `&*(ptr as *const ArcInner<T>)`, but this created a misaligned
1086
1086
// reference (see #54908).
1087
1087
let layout = Layout :: new :: < ArcInner < ( ) > > ( ) . extend ( value_layout) . unwrap ( ) . 0 . pad_to_align ( ) ;
1088
-
1089
- let ptr = allocate ( layout) . unwrap_or_else ( |_| handle_alloc_error ( layout) ) ;
1090
-
1091
- // Initialize the ArcInner
1092
- let inner = mem_to_arcinner ( ptr. as_non_null_ptr ( ) . as_ptr ( ) ) ;
1093
- debug_assert_eq ! ( unsafe { Layout :: for_value( & * inner) } , layout) ;
1094
-
1095
1088
unsafe {
1096
- ptr :: write ( & mut ( * inner ) . strong , atomic :: AtomicUsize :: new ( 1 ) ) ;
1097
- ptr :: write ( & mut ( * inner ) . weak , atomic :: AtomicUsize :: new ( 1 ) ) ;
1089
+ Arc :: try_allocate_for_layout ( value_layout , allocate , mem_to_arcinner )
1090
+ . unwrap_or_else ( |_| handle_alloc_error ( layout ) )
1098
1091
}
1099
-
1100
- inner
1101
1092
}
1102
1093
1103
1094
/// Allocates an `ArcInner<T>` with sufficient space for
You can’t perform that action at this time.
0 commit comments