From ead845ff330fdd09e408217f5641424f1cec3d17 Mon Sep 17 00:00:00 2001 From: Mike Welsh Date: Sat, 26 Sep 2020 18:19:37 -0700 Subject: [PATCH] chore: Appease clippy --- core/src/avm2/value.rs | 8 ++++---- desktop/src/audio.rs | 38 +++++++++++++++++++------------------- exporter/src/main.rs | 6 +++--- 3 files changed, 26 insertions(+), 26 deletions(-) diff --git a/core/src/avm2/value.rs b/core/src/avm2/value.rs index 7c984d3cb..68eaadb16 100644 --- a/core/src/avm2/value.rs +++ b/core/src/avm2/value.rs @@ -400,10 +400,10 @@ impl<'gc> Value<'gc> { n } else { - let (sign, digits) = if strim.starts_with('+') { - (1.0, &strim[1..]) - } else if strim.starts_with('-') { - (-1.0, &strim[1..]) + let (sign, digits) = if let Some(stripped) = strim.strip_prefix('+') { + (1.0, stripped) + } else if let Some(stripped) = strim.strip_prefix('-') { + (-1.0, stripped) } else { (1.0, strim) }; diff --git a/desktop/src/audio.rs b/desktop/src/audio.rs index 88338d839..b5a86080a 100644 --- a/desktop/src/audio.rs +++ b/desktop/src/audio.rs @@ -35,7 +35,7 @@ type Error = Box; /// A `Sound` is defined by the `DefineSound` SWF tags. struct Sound { format: swf::SoundFormat, - data: Arc>, + data: Arc<[u8]>, /// Number of samples in this audio. /// This does not include the skip_sample_frames. num_sample_frames: u32, @@ -147,7 +147,7 @@ impl CpalAudioBackend { /// Instantiate a seeabkle decoder for the compression that the sound data uses. fn make_seekable_decoder( format: &swf::SoundFormat, - data: Cursor, + data: Cursor, ) -> Result, Error> { let decoder: Box = match format.compression { AudioCompression::Uncompressed => Box::new(PcmDecoder::new( @@ -201,7 +201,7 @@ impl CpalAudioBackend { &self, sound: &Sound, settings: &swf::SoundInfo, - data: Cursor, + data: Cursor, ) -> Result>, Error> { // Instantiate a decoder for the compression that the sound data uses. let decoder = Self::make_seekable_decoder(&sound.format, data)?; @@ -308,7 +308,7 @@ impl AudioBackend for CpalAudioBackend { let sound = Sound { format: swf_sound.format.clone(), - data: Arc::new(data.to_vec()), + data: Arc::from(data), num_sample_frames: swf_sound.num_samples, skip_sample_frames, }; @@ -350,7 +350,7 @@ impl AudioBackend for CpalAudioBackend { settings: &swf::SoundInfo, ) -> Result { let sound = &self.sounds[sound_handle]; - let data = Cursor::new(VecAsRef(Arc::clone(&sound.data))); + let data = Cursor::new(ArcAsRef(Arc::clone(&sound.data))); // Create a signal that decodes and resamples the sound. let signal = if sound.skip_sample_frames == 0 && settings.in_sample.is_none() @@ -416,18 +416,18 @@ impl AudioBackend for CpalAudioBackend { /// A dummy wrapper struct to implement `AsRef<[u8]>` for `Arc`. /// Not having this trait causes problems when trying to use `Cursor>`. -struct VecAsRef(Arc>); +struct ArcAsRef(Arc<[u8]>); -impl AsRef<[u8]> for VecAsRef { +impl AsRef<[u8]> for ArcAsRef { #[inline] fn as_ref(&self) -> &[u8] { &self.0 } } -impl Default for VecAsRef { +impl Default for ArcAsRef { fn default() -> Self { - VecAsRef(Arc::new(vec![])) + ArcAsRef(Arc::new([])) } } @@ -546,7 +546,7 @@ impl EnvelopeSignal { fn new(envelope: swf::SoundEnvelope) -> Self { // TODO: This maybe can be done more clever using the `sample` crate. let mut envelope = envelope.into_iter(); - let first_point = envelope.next().unwrap_or_else(|| swf::SoundEnvelopePoint { + let first_point = envelope.next().unwrap_or(swf::SoundEnvelopePoint { sample: 0, left_volume: 1.0, right_volume: 1.0, @@ -587,15 +587,15 @@ impl sample::signal::Signal for EnvelopeSignal { self.cur_sample = self.cur_sample.saturating_add(1); while self.cur_sample > self.next_point.sample { self.prev_point = self.next_point.clone(); - self.next_point = - self.envelope - .next() - .clone() - .unwrap_or_else(|| swf::SoundEnvelopePoint { - sample: std::u32::MAX, - left_volume: self.prev_point.left_volume, - right_volume: self.prev_point.right_volume, - }); + self.next_point = self + .envelope + .next() + .clone() + .unwrap_or(swf::SoundEnvelopePoint { + sample: std::u32::MAX, + left_volume: self.prev_point.left_volume, + right_volume: self.prev_point.right_volume, + }); if self.prev_point.sample > self.next_point.sample { self.next_point.sample = self.prev_point.sample; diff --git a/exporter/src/main.rs b/exporter/src/main.rs index bc163d683..9e24f0020 100644 --- a/exporter/src/main.rs +++ b/exporter/src/main.rs @@ -341,9 +341,9 @@ fn main() -> Result<(), Box> { power_preference: wgpu::PowerPreference::Default, compatible_surface: None, })) - .ok_or_else(|| { - "This tool requires hardware acceleration, but no compatible graphics device was found." - })?; + .ok_or( + "This tool requires hardware acceleration, but no compatible graphics device was found.", + )?; let (device, queue) = block_on(adapter.request_device( &wgpu::DeviceDescriptor {