Unnecessary unsafe in `new_atomic_u64_array`
Boscop opened this issue · comments
HVM/src/runtime/base/memory.rs
Lines 394 to 398 in 9a6f6ff
This could just be vec![0; n].into_iter().map(|x| AtomicU64::new(x)).collect::<Vec<_>>().into_boxed_slice()
, it compiles to a call to alloc_zeroed
without any memset
(it reuses the allocated Vec):
https://godbolt.org/z/Ebrn4aaW7
(Btw, when using Box::from_raw
, it's more recommended to pair it with Box::into_raw
:
https://users.rust-lang.org/t/can-box-leak-be-complemented-with-box-from-raw/64478/2
So it would be written as Box::into_raw(...) as *mut [AtomicU64]
and a static assertion that they have the same alignment requirement.)
Or just vec![0u64; size].into_iter().map(AtomicU64::new).collect()