Skip to content

Commit

Permalink
Use copy_nonoverlapping for more efficient sequence filling
Browse files Browse the repository at this point in the history
  • Loading branch information
tobiasstarkwayve committed Oct 8, 2024
1 parent 00bd39e commit c8b5e95
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions r2r/src/nodes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1239,9 +1239,9 @@ impl Node {
let types = unsafe { std::slice::from_raw_parts(tnat.types, tnat.names.size) };

for (n, t) in names.iter().zip(types) {
assert!(*n != std::ptr::null_mut());
assert!(!(*n).is_null());
let topic_name = unsafe { CStr::from_ptr(*n).to_str().unwrap().to_owned() };
assert!(t != std::ptr::null_mut());
assert!(!t.data.is_null());
let topic_types = unsafe { std::slice::from_raw_parts(t, t.size) };
let topic_types: Vec<String> = unsafe {
topic_types
Expand Down
4 changes: 2 additions & 2 deletions r2r_rcl/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()); }
}
}

Expand All @@ -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
Expand Down

0 comments on commit c8b5e95

Please sign in to comment.