File tree Expand file tree Collapse file tree 3 files changed +24
-12
lines changed
crossbeam-channel/src/flavors Expand file tree Collapse file tree 3 files changed +24
-12
lines changed Original file line number Diff line number Diff line change @@ -72,18 +72,22 @@ struct Block<T> {
72
72
}
73
73
74
74
impl < T > Block < T > {
75
- /// Creates an empty block.
76
- fn new ( ) -> Box < Self > {
75
+ const LAYOUT : Layout = {
77
76
let layout = Layout :: new :: < Self > ( ) ;
78
77
assert ! (
79
78
layout. size( ) != 0 ,
80
79
"Block should never be zero-sized, as it has an AtomicPtr field"
81
80
) ;
81
+ layout
82
+ } ;
83
+
84
+ /// Creates an empty block.
85
+ fn new ( ) -> Box < Self > {
82
86
// SAFETY: layout is not zero-sized
83
- let ptr = unsafe { alloc_zeroed ( layout ) } ;
87
+ let ptr = unsafe { alloc_zeroed ( Self :: LAYOUT ) } ;
84
88
// Handle allocation failure
85
89
if ptr. is_null ( ) {
86
- handle_alloc_error ( layout )
90
+ handle_alloc_error ( Self :: LAYOUT )
87
91
}
88
92
// SAFETY: This is safe because:
89
93
// [1] `Block::next` (AtomicPtr) may be safely zero initialized.
Original file line number Diff line number Diff line change @@ -1225,18 +1225,22 @@ struct Block<T> {
1225
1225
}
1226
1226
1227
1227
impl < T > Block < T > {
1228
- /// Creates an empty block.
1229
- fn new ( ) -> Box < Self > {
1228
+ const LAYOUT : Layout = {
1230
1229
let layout = Layout :: new :: < Self > ( ) ;
1231
1230
assert ! (
1232
1231
layout. size( ) != 0 ,
1233
1232
"Block should never be zero-sized, as it has an AtomicPtr field"
1234
1233
) ;
1234
+ layout
1235
+ } ;
1236
+
1237
+ /// Creates an empty block.
1238
+ fn new ( ) -> Box < Self > {
1235
1239
// SAFETY: layout is not zero-sized
1236
- let ptr = unsafe { alloc_zeroed ( layout ) } ;
1240
+ let ptr = unsafe { alloc_zeroed ( Self :: LAYOUT ) } ;
1237
1241
// Handle allocation failure
1238
1242
if ptr. is_null ( ) {
1239
- handle_alloc_error ( layout )
1243
+ handle_alloc_error ( Self :: LAYOUT )
1240
1244
}
1241
1245
// SAFETY: This is safe because:
1242
1246
// [1] `Block::next` (AtomicPtr) may be safely zero initialized.
Original file line number Diff line number Diff line change @@ -58,18 +58,22 @@ struct Block<T> {
58
58
}
59
59
60
60
impl < T > Block < T > {
61
- /// Creates an empty block.
62
- fn new ( ) -> Box < Self > {
61
+ const LAYOUT : Layout = {
63
62
let layout = Layout :: new :: < Self > ( ) ;
64
63
assert ! (
65
64
layout. size( ) != 0 ,
66
65
"Block should never be zero-sized, as it has an AtomicPtr field"
67
66
) ;
67
+ layout
68
+ } ;
69
+
70
+ /// Creates an empty block.
71
+ fn new ( ) -> Box < Self > {
68
72
// SAFETY: layout is not zero-sized
69
- let ptr = unsafe { alloc_zeroed ( layout ) } ;
73
+ let ptr = unsafe { alloc_zeroed ( Self :: LAYOUT ) } ;
70
74
// Handle allocation failure
71
75
if ptr. is_null ( ) {
72
- handle_alloc_error ( layout )
76
+ handle_alloc_error ( Self :: LAYOUT )
73
77
}
74
78
// SAFETY: This is safe because:
75
79
// [1] `Block::next` (AtomicPtr) may be safely zero initialized.
You can’t perform that action at this time.
0 commit comments