Skip to content

Commit

Permalink
Accelerate z_bytes_to_slice
Browse files Browse the repository at this point in the history
  • Loading branch information
fuzzypixelz committed Nov 14, 2024
1 parent 1d688a7 commit 06fcc5e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
7 changes: 7 additions & 0 deletions src/collections.rs
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,13 @@ impl From<Vec<u8>> for CSliceOwned {
}
}

impl From<Box<[u8]>> for CSliceOwned {
fn from(value: Box<[u8]>) -> Self {
let slice = Box::leak(value);
CSliceOwned(CSlice::wrap(slice.as_ptr(), slice.len()))
}
}

impl From<Vec<u8>> for CSlice {
fn from(value: Vec<u8>) -> Self {
let slice: CSliceOwned = value.into();
Expand Down
2 changes: 1 addition & 1 deletion src/zbytes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ pub unsafe extern "C" fn z_bytes_to_slice(
) -> z_result_t {
let payload = this.as_rust_type_ref();
dst.as_rust_type_mut_uninit()
.write(payload.to_bytes().into_owned().into());
.write(CSliceOwned::from(Box::<[u8]>::from(payload.to_bytes())));
result::Z_OK
}

Expand Down

0 comments on commit 06fcc5e

Please sign in to comment.