Skip to content

Commit d804258

Browse files
committed
Don't create sub-array unless necessary
1 parent 1dbda17 commit d804258

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
@@ -28,7 +28,11 @@ pub fn fill_inner(dest: &mut [MaybeUninit<u8>]) -> Result<(), Error> {
2828
.expect("chunk length is bounded by CRYPTO_BUFFER_SIZE");
2929
// The chunk can be smaller than buf's length, so we call to
3030
// JS to create a smaller view of buf without allocation.
31-
let sub_buf = buf.subarray(0, chunk_len);
31+
let sub_buf = if chunk_len == u32::from(CRYPTO_BUFFER_SIZE) {
32+
buf.clone()
33+
} else {
34+
buf.subarray(0, chunk_len)
35+
};
3236

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

0 commit comments

Comments
 (0)