From 9ef53f5ffb2cc3acc134854dffa2ef45e119a170 Mon Sep 17 00:00:00 2001 From: JasonLG1979 Date: Wed, 6 Oct 2021 11:20:09 -0500 Subject: [PATCH] simplify buffer resizing This way is less verbose, much more simple and less brittle. --- playback/src/audio_backend/alsa.rs | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/playback/src/audio_backend/alsa.rs b/playback/src/audio_backend/alsa.rs index 41c75ed6..9dd3ea0c 100644 --- a/playback/src/audio_backend/alsa.rs +++ b/playback/src/audio_backend/alsa.rs @@ -7,7 +7,6 @@ use alsa::device_name::HintIter; use alsa::pcm::{Access, Format, HwParams, PCM}; use alsa::{Direction, ValueOr}; use std::cmp::min; -use std::cmp::Ordering; use std::process::exit; use std::time::Duration; use thiserror::Error; @@ -226,16 +225,8 @@ impl Sink for AlsaSink { let (pcm, bytes_per_period) = open_device(&self.device, self.format)?; self.pcm = Some(pcm); - match self.period_buffer.capacity().cmp(&bytes_per_period) { - Ordering::Greater => { - self.period_buffer.truncate(bytes_per_period); - self.period_buffer.shrink_to_fit(); - } - Ordering::Less => { - let extra = bytes_per_period - self.period_buffer.len(); - self.period_buffer.reserve_exact(extra); - } - Ordering::Equal => (), + if self.period_buffer.capacity() != bytes_per_period { + self.period_buffer = Vec::with_capacity(bytes_per_period); } // Should always match the "Period Buffer size in bytes: " trace! message.