Grid: move around unsafe block

This commit is contained in:
Simon Gardling 2025-03-27 14:45:14 -04:00
parent 985fb73042
commit ab70ce7f53
Signed by: titaniumtown
GPG Key ID: 9AB28AC10ECE533D

View File

@ -140,13 +140,12 @@ where
let bufs: Vec<_> = grids.iter().map(|grid| &grid.buf.buf).collect();
// We mutate grid buffers and read grid data. We use unsafe because we need shared/unique borrows on different fields of the same Grid struct.
bufs.iter().enumerate().for_each(|(i, buf)| unsafe {
bufs.iter().enumerate().for_each(|(i, buf)| {
let buf_ptr = *buf as *const Vec<f32> as *mut Vec<f32>;
buf_ptr.as_mut().unwrap().fill(0.0);
unsafe { buf_ptr.as_mut() }.unwrap().fill(0.0);
datas.iter().enumerate().for_each(|(j, other)| {
let multiplier = attraction_table[i].as_ref()[j];
buf_ptr
.as_mut()
unsafe { buf_ptr.as_mut() }
.unwrap()
.iter_mut()
.zip(*other)