@@ -359,30 +359,33 @@ pub fn fill_bytes_via_gen_block<W: Word, const N: usize>(
359359 let buf_rem = size_of_val ( buf_tail) ;
360360
361361 if buf_rem >= dst. len ( ) {
362- let new_pos = read_bytes ( & buf, dst, pos) ;
362+ let new_pos = read_bytes ( buf, dst, pos) ;
363363 buf[ 0 ] = new_pos;
364364 return ;
365365 }
366366
367367 let ( l, r) = dst. split_at_mut ( buf_rem) ;
368- read_bytes ( & buf, l, pos) ;
368+ read_bytes ( buf, l, pos) ;
369369 dst = r;
370370 }
371371
372372 let mut blocks = dst. chunks_exact_mut ( N * word_size) ;
373373 let zero = W :: from_usize ( 0 ) ;
374- let mut temp_buf = [ zero; N ] ;
375374 for block in & mut blocks {
376- generate_block ( & mut temp_buf) ;
377- read_bytes ( & temp_buf, block, zero) ;
375+ // We intentionally use the temporary buffer to prevent unnecessary writes
376+ // to the original `buf` and to enable potential optimization of writing
377+ // generated data directly into `block`.
378+ let mut buf = [ zero; N ] ;
379+ generate_block ( & mut buf) ;
380+ read_bytes ( & buf, block, zero) ;
378381 }
379382
380383 let rem = blocks. into_remainder ( ) ;
381384 let new_pos = if rem. is_empty ( ) {
382385 W :: from_usize ( N )
383386 } else {
384387 generate_block ( buf) ;
385- read_bytes :: < W , N > ( & buf, rem, zero)
388+ read_bytes :: < W , N > ( buf, rem, zero)
386389 } ;
387390 buf[ 0 ] = new_pos;
388391}
0 commit comments