Skip to content

Commit

Permalink
Simplify the rayon calls in the installer
Browse files Browse the repository at this point in the history
Rayon's `try_for_each` makes the `CombinedEncoder` a lot simpler.
  • Loading branch information
cuviper committed Jun 5, 2024
1 parent db8aca4 commit c0e2543
Showing 1 changed file with 3 additions and 9 deletions.
12 changes: 3 additions & 9 deletions src/tools/rust-installer/src/compression.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,22 +214,16 @@ impl Write for CombinedEncoder {
}

fn write_all(&mut self, buf: &[u8]) -> std::io::Result<()> {
self.encoders
.par_iter_mut()
.map(|w| w.write_all(buf))
.collect::<std::io::Result<Vec<()>>>()?;
Ok(())
self.encoders.par_iter_mut().try_for_each(|w| w.write_all(buf))
}

fn flush(&mut self) -> std::io::Result<()> {
self.encoders.par_iter_mut().map(|w| w.flush()).collect::<std::io::Result<Vec<()>>>()?;
Ok(())
self.encoders.par_iter_mut().try_for_each(Write::flush)
}
}

impl Encoder for CombinedEncoder {
fn finish(self: Box<Self>) -> Result<(), Error> {
self.encoders.into_par_iter().map(|e| e.finish()).collect::<Result<Vec<()>, Error>>()?;
Ok(())
self.encoders.into_par_iter().try_for_each(Encoder::finish)
}
}

0 comments on commit c0e2543

Please sign in to comment.