Use copy_nonoverlapping for more efficient sequence filling

This commit is contained in:
Tobias Stark 2024-10-09 07:47:02 +00:00 committed by Martin Dahl
parent 6311c2013f
commit 94ceec8cf6
1 changed files with 2 additions and 2 deletions

View File

@ -116,7 +116,7 @@ macro_rules! primitive_sequence {
unsafe { [<$ctype __Sequence__fini>] (self as *mut _); }
unsafe { [<$ctype __Sequence__init>] (self as *mut _, values.len()); }
if self.data != std::ptr::null_mut() {
unsafe { std::ptr::copy(values.as_ptr(), self.data, values.len()); }
unsafe { std::ptr::copy_nonoverlapping(values.as_ptr(), self.data, values.len()); }
}
}
@ -126,7 +126,7 @@ macro_rules! primitive_sequence {
}
let mut target = Vec::with_capacity(self.size);
unsafe {
std::ptr::copy(self.data, target.as_mut_ptr(), self.size);
std::ptr::copy_nonoverlapping(self.data, target.as_mut_ptr(), self.size);
target.set_len(self.size);
}
target