From b5b6014edf0da61f72840adefe8cadd2aac64479 Mon Sep 17 00:00:00 2001 From: Rob Watson Date: Thu, 10 Sep 2020 15:50:35 +0200 Subject: [PATCH 1/2] wasm backends: Fix default_output_config behaviour --- src/host/emscripten/mod.rs | 2 +- src/host/webaudio/mod.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/host/emscripten/mod.rs b/src/host/emscripten/mod.rs index dbf5078..07505aa 100644 --- a/src/host/emscripten/mod.rs +++ b/src/host/emscripten/mod.rs @@ -107,7 +107,7 @@ impl Device { configs.sort_by(|a, b| a.cmp_default_heuristics(b)); let config = configs .into_iter() - .next() + .last() .expect(EXPECT) .with_sample_rate(DEFAULT_SAMPLE_RATE); Ok(config) diff --git a/src/host/webaudio/mod.rs b/src/host/webaudio/mod.rs index f58f18c..6db820a 100644 --- a/src/host/webaudio/mod.rs +++ b/src/host/webaudio/mod.rs @@ -125,7 +125,7 @@ impl Device { configs.sort_by(|a, b| a.cmp_default_heuristics(b)); let config = configs .into_iter() - .next() + .last() .expect(EXPECT) .with_sample_rate(DEFAULT_SAMPLE_RATE); Ok(config) From 0b300afefe17f60d3b4efb4e896733566ef4f42a Mon Sep 17 00:00:00 2001 From: Rob Watson Date: Fri, 11 Sep 2020 11:34:23 +0200 Subject: [PATCH 2/2] 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) } }