#[derive(Debug, PartialEq, Eq, Clone, Hash)]
pub struct CopyFromPatch {
pub src_addr: usize,
pub dst_addr: usize,
pub size: usize,
}
pub fn apply_patches(new_storage: &mut [u64], old_storage: &[u64], patches: &[CopyFromPatch]) {
for patch in patches {
let src_end = patch.src_addr + patch.size;
let dst_end = patch.dst_addr + patch.size;
debug_assert!(
src_end <= old_storage.len(),
"Source address range [{}, {}) exceeds old storage size {}",
patch.src_addr,
src_end,
old_storage.len()
);
debug_assert!(
dst_end <= new_storage.len(),
"Destination address range [{}, {}) exceeds new storage size {}",
patch.dst_addr,
dst_end,
new_storage.len()
);
new_storage[patch.dst_addr..dst_end].copy_from_slice(&old_storage[patch.src_addr..src_end]);
}
}