From faa1ef1fb892077e5dba79e355745fc147cd3810 Mon Sep 17 00:00:00 2001 From: Antoine Martin Date: Wed, 8 Apr 2020 19:31:46 +0200 Subject: [PATCH] library: render: pathtracer: avoid row allocation --- pathtracer/src/render/pathtrace/pathtracer.rs | 21 ++++++------------- 1 file changed, 6 insertions(+), 15 deletions(-) diff --git a/pathtracer/src/render/pathtrace/pathtracer.rs b/pathtracer/src/render/pathtrace/pathtracer.rs index b052642..2699086 100644 --- a/pathtracer/src/render/pathtrace/pathtracer.rs +++ b/pathtracer/src/render/pathtrace/pathtracer.rs @@ -49,25 +49,16 @@ impl Pathtracer { let mut buffer: Vec = Vec::new(); buffer.resize_with(total as usize, LinearColor::black); - (0..height) - .into_par_iter() - .map(|y| { - let mut row: Vec = Vec::new(); - row.resize_with(width as usize, LinearColor::black); - + buffer + .par_chunks_mut(width as usize) + .enumerate() + .for_each(|(y, row)| { for x in 0..width { row[x as usize] += self.pixel_ray(x as f32, y as f32); } + }); - row - }) - .reduce( - || Vec::new(), - |mut buf, row| { - buf.extend(row); - buf - }, - ) + buffer }) .fold( {