Skip to content

Commit 6eb122a

Browse files
committed
move Alloc trait methods as WeeAlloc methods
1 parent 573e70c commit 6eb122a

File tree

1 file changed

+18
-11
lines changed

1 file changed

+18
-11
lines changed

wee_alloc/src/lib.rs

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1069,13 +1069,8 @@ impl<'a> WeeAlloc<'a> {
10691069
result
10701070
})
10711071
}
1072-
}
10731072

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> {
10791074
let size = Bytes(layout.size());
10801075
let align = if layout.align() == 0 {
10811076
Bytes(1)
@@ -1098,7 +1093,7 @@ where
10981093
})
10991094
}
11001095

1101-
unsafe fn dealloc(&mut self, ptr: NonNull<u8>, layout: Layout) {
1096+
unsafe fn dealloc_impl(&self, ptr: NonNull<u8>, layout: Layout) {
11021097
let size = Bytes(layout.size());
11031098
if size.0 == 0 {
11041099
return;
@@ -1187,19 +1182,31 @@ where
11871182
}
11881183
}
11891184

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+
11901199
unsafe impl GlobalAlloc for WeeAlloc<'static> {
11911200
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) {
11941202
Ok(ptr) => ptr.as_ptr(),
11951203
Err(AllocErr) => 0 as *mut u8,
11961204
}
11971205
}
11981206

11991207
unsafe fn dealloc(&self, ptr: *mut u8, layout: Layout) {
12001208
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);
12031210
}
12041211
}
12051212
}

0 commit comments

Comments
 (0)