Skip to content

Commit

Permalink
Don't create sub-array unless necessary
Browse files Browse the repository at this point in the history
  • Loading branch information
daxpedda committed Dec 6, 2024
1 parent aee9640 commit 254d512
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/backends/wasm_js.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,11 @@ pub fn fill_inner(dest: &mut [MaybeUninit<u8>]) -> Result<(), Error> {
.expect("chunk length is bounded by CRYPTO_BUFFER_SIZE");
// The chunk can be smaller than buf's length, so we call to
// JS to create a smaller view of buf without allocation.
let sub_buf = buf.subarray(0, chunk_len);
let sub_buf = if chunk_len == u32::from(CRYPTO_BUFFER_SIZE) {
buf.clone()
} else {
buf.subarray(0, chunk_len)
};

if crypto.get_random_values(&sub_buf).is_err() {
return Err(Error::WEB_GET_RANDOM_VALUES);
Expand Down

0 comments on commit 254d512

Please sign in to comment.