From 254d5123a17f1c43393a7608dc537c671a4e0003 Mon Sep 17 00:00:00 2001 From: daxpedda Date: Fri, 6 Dec 2024 09:30:50 +0100 Subject: [PATCH] Don't create sub-array unless necessary --- src/backends/wasm_js.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/backends/wasm_js.rs b/src/backends/wasm_js.rs index 8837dab5..d42e62db 100644 --- a/src/backends/wasm_js.rs +++ b/src/backends/wasm_js.rs @@ -29,7 +29,11 @@ pub fn fill_inner(dest: &mut [MaybeUninit]) -> 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);