@@ -1069,13 +1069,8 @@ impl<'a> WeeAlloc<'a> {
1069
1069
result
1070
1070
} )
1071
1071
}
1072
- }
1073
1072
1074
- unsafe impl < ' a , ' b > Alloc for & ' b WeeAlloc < ' a >
1075
- where
1076
- ' a : ' b ,
1077
- {
1078
- unsafe fn alloc ( & mut self , layout : Layout ) -> Result < NonNull < u8 > , AllocErr > {
1073
+ unsafe fn alloc_impl ( & self , layout : Layout ) -> Result < NonNull < u8 > , AllocErr > {
1079
1074
let size = Bytes ( layout. size ( ) ) ;
1080
1075
let align = if layout. align ( ) == 0 {
1081
1076
Bytes ( 1 )
@@ -1098,7 +1093,7 @@ where
1098
1093
} )
1099
1094
}
1100
1095
1101
- unsafe fn dealloc ( & mut self , ptr : NonNull < u8 > , layout : Layout ) {
1096
+ unsafe fn dealloc_impl ( & self , ptr : NonNull < u8 > , layout : Layout ) {
1102
1097
let size = Bytes ( layout. size ( ) ) ;
1103
1098
if size. 0 == 0 {
1104
1099
return ;
@@ -1187,19 +1182,31 @@ where
1187
1182
}
1188
1183
}
1189
1184
1185
+ #[ cfg( nightly) ]
1186
+ unsafe impl < ' a , ' b > Alloc for & ' b WeeAlloc < ' a >
1187
+ where
1188
+ ' a : ' b ,
1189
+ {
1190
+ unsafe fn alloc ( & mut self , layout : Layout ) -> Result < NonNull < u8 > , AllocErr > {
1191
+ self . alloc_impl ( layout)
1192
+ }
1193
+
1194
+ unsafe fn dealloc ( & mut self , ptr : NonNull < u8 > , layout : Layout ) {
1195
+ self . dealloc_impl ( ptr, layout)
1196
+ }
1197
+ }
1198
+
1190
1199
unsafe impl GlobalAlloc for WeeAlloc < ' static > {
1191
1200
unsafe fn alloc ( & self , layout : Layout ) -> * mut u8 {
1192
- let mut me = self ;
1193
- match Alloc :: alloc ( & mut me, layout) {
1201
+ match self . alloc_impl ( layout) {
1194
1202
Ok ( ptr) => ptr. as_ptr ( ) ,
1195
1203
Err ( AllocErr ) => 0 as * mut u8 ,
1196
1204
}
1197
1205
}
1198
1206
1199
1207
unsafe fn dealloc ( & self , ptr : * mut u8 , layout : Layout ) {
1200
1208
if let Some ( ptr) = NonNull :: new ( ptr) {
1201
- let mut me = self ;
1202
- Alloc :: dealloc ( & mut me, ptr, layout) ;
1209
+ self . dealloc_impl ( ptr, layout) ;
1203
1210
}
1204
1211
}
1205
1212
}
0 commit comments