Improve fill_zeroes' use of ptr::write_bytes (#284)

This commit is contained in:
Alphyr 2024-11-19 16:01:37 +01:00 committed by GitHub
parent 13f4ae0cdf
commit 1400815a33
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -532,8 +532,8 @@ pub fn fill_zeroes<T: Zeroable>(slice: &mut [T]) {
slice.iter_mut().for_each(write_zeroes);
} else {
// Otherwise we can be really fast and just fill everthing with zeros.
let len = core::mem::size_of_val::<[T]>(slice);
unsafe { core::ptr::write_bytes(slice.as_mut_ptr() as *mut u8, 0u8, len) }
let len = slice.len();
unsafe { core::ptr::write_bytes(slice.as_mut_ptr(), 0u8, len) }
}
}