wasm backends: Avoid a heap allocation in default_output_config()

This commit is contained in:
Rob Watson 2020-09-11 11:34:23 +02:00
parent b5b6014edf
commit 0b300afefe
2 changed files with 10 additions and 10 deletions

View file

@ -103,13 +103,13 @@ impl Device {
fn default_output_config(&self) -> Result<SupportedStreamConfig, DefaultStreamConfigError> { fn default_output_config(&self) -> Result<SupportedStreamConfig, DefaultStreamConfigError> {
const EXPECT: &str = "expected at least one valid webaudio stream config"; const EXPECT: &str = "expected at least one valid webaudio stream config";
let mut configs: Vec<_> = self.supported_output_configs().expect(EXPECT).collect(); let config = self
configs.sort_by(|a, b| a.cmp_default_heuristics(b)); .supported_output_configs()
let config = configs
.into_iter()
.last()
.expect(EXPECT) .expect(EXPECT)
.max_by(|a, b| a.cmp_default_heuristics(b))
.unwrap()
.with_sample_rate(DEFAULT_SAMPLE_RATE); .with_sample_rate(DEFAULT_SAMPLE_RATE);
Ok(config) Ok(config)
} }
} }

View file

@ -121,13 +121,13 @@ impl Device {
#[inline] #[inline]
fn default_output_config(&self) -> Result<SupportedStreamConfig, DefaultStreamConfigError> { fn default_output_config(&self) -> Result<SupportedStreamConfig, DefaultStreamConfigError> {
const EXPECT: &str = "expected at least one valid webaudio stream config"; const EXPECT: &str = "expected at least one valid webaudio stream config";
let mut configs: Vec<_> = self.supported_output_configs().expect(EXPECT).collect(); let config = self
configs.sort_by(|a, b| a.cmp_default_heuristics(b)); .supported_output_configs()
let config = configs
.into_iter()
.last()
.expect(EXPECT) .expect(EXPECT)
.max_by(|a, b| a.cmp_default_heuristics(b))
.unwrap()
.with_sample_rate(DEFAULT_SAMPLE_RATE); .with_sample_rate(DEFAULT_SAMPLE_RATE);
Ok(config) Ok(config)
} }
} }