From 0b300afefe17f60d3b4efb4e896733566ef4f42a Mon Sep 17 00:00:00 2001 From: Rob Watson Date: Fri, 11 Sep 2020 11:34:23 +0200 Subject: [PATCH] wasm backends: Avoid a heap allocation in default_output_config() --- src/host/emscripten/mod.rs | 10 +++++----- src/host/webaudio/mod.rs | 10 +++++----- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/host/emscripten/mod.rs b/src/host/emscripten/mod.rs index 07505aa..4c51f3d 100644 --- a/src/host/emscripten/mod.rs +++ b/src/host/emscripten/mod.rs @@ -103,13 +103,13 @@ impl Device { fn default_output_config(&self) -> Result { const EXPECT: &str = "expected at least one valid webaudio stream config"; - let mut configs: Vec<_> = self.supported_output_configs().expect(EXPECT).collect(); - configs.sort_by(|a, b| a.cmp_default_heuristics(b)); - let config = configs - .into_iter() - .last() + let config = self + .supported_output_configs() .expect(EXPECT) + .max_by(|a, b| a.cmp_default_heuristics(b)) + .unwrap() .with_sample_rate(DEFAULT_SAMPLE_RATE); + Ok(config) } } diff --git a/src/host/webaudio/mod.rs b/src/host/webaudio/mod.rs index 6db820a..fc138ef 100644 --- a/src/host/webaudio/mod.rs +++ b/src/host/webaudio/mod.rs @@ -121,13 +121,13 @@ impl Device { #[inline] fn default_output_config(&self) -> Result { const EXPECT: &str = "expected at least one valid webaudio stream config"; - let mut configs: Vec<_> = self.supported_output_configs().expect(EXPECT).collect(); - configs.sort_by(|a, b| a.cmp_default_heuristics(b)); - let config = configs - .into_iter() - .last() + let config = self + .supported_output_configs() .expect(EXPECT) + .max_by(|a, b| a.cmp_default_heuristics(b)) + .unwrap() .with_sample_rate(DEFAULT_SAMPLE_RATE); + Ok(config) } }