Skip to content

Commit

Permalink
fix: rename ZeroCopyVec::copy_from_slice -> extend_from_slice
Browse files Browse the repository at this point in the history
  • Loading branch information
ananas-block committed Jan 4, 2025
1 parent 72cc5dc commit 10d88fc
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion program-libs/zero-copy/src/slice_mut.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ where
}

unsafe {
std::ptr::copy_nonoverlapping(slice.as_ptr(), self.data_as_mut_ptr(), slice.len());
std::ptr::copy_nonoverlapping(slice.as_ptr(), self.data_as_mut_ptr(), len);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion program-libs/zero-copy/src/vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ where
&mut self.data.as_mut_slice()[..len]
}

pub fn copy_from_slice(&mut self, slice: &[T]) {
pub fn extend_from_slice(&mut self, slice: &[T]) {
let len = self.len();
let new_len = len + slice.len();
if new_len > self.capacity() {
Expand Down
2 changes: 1 addition & 1 deletion program-libs/zero-copy/tests/vec_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ fn test_zero_copy_vec_to_array() {
let capacity = 16;
let mut data = vec![0; ZeroCopyVecUsize::<u32>::required_size_for_capacity(capacity)];
let mut vec = ZeroCopyVecUsize::<u32>::new(capacity, &mut data).unwrap();
vec.copy_from_slice(&[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]);
vec.extend_from_slice(&[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]);

let arr: [u32; 16] = vec.try_into_array().unwrap();
assert_eq!(arr, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]);
Expand Down

0 comments on commit 10d88fc

Please sign in to comment.