Skip to content

Commit b009e84

Browse files
committed
Use ptr::write instead of mem::replace for initial hole write
1 parent 2f7837d commit b009e84

File tree

2 files changed

+4
-9
lines changed

2 files changed

+4
-9
lines changed

src/hole.rs

+3-9
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use core::ptr::Unique;
2-
use core::mem::{self, size_of};
2+
use core::mem::size_of;
33
use alloc::allocator::{Layout, AllocErr};
44

55
use super::align_up;
@@ -27,13 +27,7 @@ impl HoleList {
2727
assert!(size_of::<Hole>() == Self::min_size());
2828

2929
let ptr = hole_addr as *mut Hole;
30-
mem::replace(
31-
&mut *ptr,
32-
Hole {
33-
size: hole_size,
34-
next: None,
35-
},
36-
);
30+
ptr.write(Hole { size: hole_size, next: None, });
3731

3832
HoleList {
3933
first: Hole {
@@ -299,7 +293,7 @@ fn deallocate(mut hole: &mut Hole, addr: usize, mut size: usize) {
299293
};
300294
// write the new hole to the freed memory
301295
let ptr = addr as *mut Hole;
302-
mem::replace(unsafe { &mut *ptr }, new_hole);
296+
unsafe { ptr.write(new_hole) };
303297
// add the F block as the next block of the X block
304298
hole.next = Some(unsafe { Unique::new_unchecked(ptr) });
305299
}

src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#![feature(unique)]
22
#![feature(const_fn)]
33
#![feature(alloc, allocator_api)]
4+
#![feature(pointer_methods)]
45
#![no_std]
56
#![feature(ptr_internals)]
67

0 commit comments

Comments
 (0)