Skip to content

Commit de63b7f

Browse files
committed
Don't create sub-array unless necessary
1 parent 8d0bf4d commit de63b7f

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/backends/wasm_js.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,11 @@ pub fn fill_inner(dest: &mut [MaybeUninit<u8>]) -> Result<(), Error> {
3636
.expect("chunk length is bounded by CRYPTO_BUFFER_SIZE");
3737
// The chunk can be smaller than buf's length, so we call to
3838
// JS to create a smaller view of buf without allocation.
39-
let sub_buf = buf.subarray(0, chunk_len);
39+
let sub_buf = if chunk_len == u32::from(CRYPTO_BUFFER_SIZE) {
40+
buf.clone()
41+
} else {
42+
buf.subarray(0, chunk_len)
43+
};
4044

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

0 commit comments

Comments
 (0)