replace vec.truncate(0) with vec.clear()
authorKostya Shishkov <kostya.shishkov@gmail.com>
Fri, 29 Oct 2021 12:34:43 +0000 (14:34 +0200)
committerKostya Shishkov <kostya.shishkov@gmail.com>
Fri, 29 Oct 2021 12:34:43 +0000 (14:34 +0200)
sndplay/src/main.rs
videoplayer/src/audiodec.rs
videoplayer/src/videodec.rs

index 39ee76dee8edfd164ec99079d929e6a7d71dc301..618c2271b14c9950d8d6429a93ce0d542baf0ec6 100644 (file)
@@ -107,7 +107,7 @@ struct Decoder<'a> {
 
 fn output_vol_i16(device: &AudioDevice, tmp: &mut Vec<i16>, src: &[i16], mute: bool, volume: u8) {
     if !mute {
-        tmp.truncate(0);
+        tmp.clear();
         tmp.reserve(src.len());
         let vol = i32::from(volume);
         for &sample in src.iter() {
@@ -115,7 +115,7 @@ fn output_vol_i16(device: &AudioDevice, tmp: &mut Vec<i16>, src: &[i16], mute: b
             tmp.push(nsamp.min(32767).max(-32768) as i16);
         }
     } else {
-        tmp.truncate(0);
+        tmp.clear();
         tmp.resize(src.len(), 0);
     }
     device.queue(&tmp);
@@ -123,7 +123,7 @@ fn output_vol_i16(device: &AudioDevice, tmp: &mut Vec<i16>, src: &[i16], mute: b
 
 fn output_vol_u8(device: &AudioDevice, tmp: &mut Vec<i16>, src: &[u8], mute: bool, volume: u8) {
     if !mute {
-        tmp.truncate(0);
+        tmp.clear();
         tmp.reserve(src.len());
         let vol = i32::from(volume);
         for sample in src.chunks_exact(2) {
@@ -132,7 +132,7 @@ fn output_vol_u8(device: &AudioDevice, tmp: &mut Vec<i16>, src: &[u8], mute: boo
             tmp.push(nsamp.min(32767).max(-32768) as i16);
         }
     } else {
-        tmp.truncate(0);
+        tmp.clear();
         tmp.resize(src.len() / 2, 0);
     }
     device.queue(&tmp);
index dcc564931cb3bf539789582e61dc7a07e4074128..304519294c487b805397e62e752c5dcc1d0c8d1b 100644 (file)
@@ -343,7 +343,7 @@ impl AudioControl {
 
     pub fn flush(&mut self) {
         self.pause();
-        self.aqueue.truncate(0);
+        self.aqueue.clear();
         SKIP_ADECODING.store(true, Ordering::Release);
         CURRENT_TIME_SET.store(false, Ordering::Release);
         let _ = self.apsend.send(PktSendEvent::Flush);
index b8867f1ad46f947d972ca267e0cb74c407688266..0a1dcd59220737411ef82e68a5c58f6f46a6327c 100644 (file)
@@ -246,7 +246,7 @@ impl VideoControl {
         }
     }
     pub fn flush(&mut self) {
-        self.vqueue.truncate(0);
+        self.vqueue.clear();
         SKIP_VDECODING.store(true, Ordering::Release);
         for _ in 0..8 {
             let _ = self.vfrecv.try_recv();