Skip to content

Commit 254d512

Browse files
committed
Don't create sub-array unless necessary
1 parent aee9640 commit 254d512

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/backends/wasm_js.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,11 @@ pub fn fill_inner(dest: &mut [MaybeUninit<u8>]) -> Result<(), Error> {
2929
.expect("chunk length is bounded by CRYPTO_BUFFER_SIZE");
3030
// The chunk can be smaller than buf's length, so we call to
3131
// JS to create a smaller view of buf without allocation.
32-
let sub_buf = buf.subarray(0, chunk_len);
32+
let sub_buf = if chunk_len == u32::from(CRYPTO_BUFFER_SIZE) {
33+
buf.clone()
34+
} else {
35+
buf.subarray(0, chunk_len)
36+
};
3337

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

0 commit comments

Comments
 (0)