From 9d50532093a1984b217d1b4fa9a396147aa5c49a Mon Sep 17 00:00:00 2001 From: Colin Rofls Date: Thu, 29 Jul 2021 17:08:21 -0400 Subject: [PATCH] Use rayon when serializing glyphs --- src/layer.rs | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/layer.rs b/src/layer.rs index 17161d7e..0089ec6c 100644 --- a/src/layer.rs +++ b/src/layer.rs @@ -334,12 +334,16 @@ impl Layer { if !self.layerinfo_is_empty() { self.layerinfo_to_file(path)?; } - for (name, glyph_path) in self.contents.iter() { - let glyph = self.glyphs.get(name).expect("all glyphs in contents must exist."); - glyph.save(path.join(glyph_path))?; - } - Ok(()) + #[cfg(feature = "rayon")] + let iter = self.contents.par_iter(); + #[cfg(not(feature = "rayon"))] + let mut iter = self.contents.iter(); + + iter.try_for_each(|(name, glyph_path)| { + let glyph = self.glyphs.get(name).expect("all glyphs in contents must exist."); + glyph.save(path.join(glyph_path)) + }) } /// The number of [`Glyph`]s in the layer.