From: Kostya Shishkov Date: Fri, 8 Nov 2024 19:03:40 +0000 (+0100) Subject: nihav_qt: fix or update clippy warnings X-Git-Url: https://git.nihav.org/?a=commitdiff_plain;h=27116a4ce3a107039019d8153cbfa10d0e46e037;p=nihav.git nihav_qt: fix or update clippy warnings --- diff --git a/nihav-qt/src/codecs/alac.rs b/nihav-qt/src/codecs/alac.rs index 6443917..56cab1d 100644 --- a/nihav-qt/src/codecs/alac.rs +++ b/nihav-qt/src/codecs/alac.rs @@ -98,6 +98,7 @@ impl PredInfo { } Ok(()) } + #[allow(clippy::comparison_chain)] fn lpc_pred(&mut self, samps: &mut [i32], bits: u8) { if self.mode == 15 || self.order == 31 { for i in 1..samps.len() { @@ -153,7 +154,7 @@ impl ALACDecoder { kb: 0, } } - #[allow(clippy::collapsible_if)] + #[allow(clippy::collapsible_else_if)] fn decode_elem(&mut self, br: &mut BitReader, stereo: bool) -> DecoderResult<()> { let _element_instance = br.read(4)?; br.skip(12)?; diff --git a/nihav-qt/src/codecs/mod.rs b/nihav-qt/src/codecs/mod.rs index d06c401..5c1ddc4 100644 --- a/nihav-qt/src/codecs/mod.rs +++ b/nihav-qt/src/codecs/mod.rs @@ -24,19 +24,13 @@ mod svq1; mod svq1data; #[cfg(feature="decoder_svq3")] -#[allow(clippy::collapsible_if)] -#[allow(clippy::identity_op)] -#[allow(clippy::needless_range_loop)] #[allow(clippy::too_many_arguments)] -#[allow(clippy::verbose_bit_mask)] mod svq3; #[cfg(feature="decoder_svq3")] -#[allow(clippy::collapsible_if)] +#[allow(clippy::collapsible_else_if)] #[allow(clippy::erasing_op)] #[allow(clippy::identity_op)] #[allow(clippy::many_single_char_names)] -#[allow(clippy::needless_range_loop)] -#[allow(clippy::unreadable_literal)] mod svq3dsp; #[cfg(feature="decoder_alac")] @@ -49,25 +43,17 @@ mod imaadpcm; mod mace; #[cfg(any(feature="decoder_qdm",feature="decoder_qdm2"))] -#[allow(clippy::unreadable_literal)] mod qdmcommon; #[cfg(feature="decoder_qdm")] -#[allow(clippy::needless_range_loop)] -#[allow(clippy::unreadable_literal)] mod qdmc; #[cfg(feature="decoder_qdm2")] -#[allow(clippy::needless_range_loop)] #[allow(clippy::excessive_precision)] -#[allow(clippy::unreadable_literal)] mod qdm2fft; #[cfg(feature="decoder_qdm2")] -#[allow(clippy::needless_range_loop)] #[allow(clippy::excessive_precision)] -#[allow(clippy::unreadable_literal)] mod qdm2qmf; #[cfg(feature="decoder_qdm2")] #[allow(clippy::excessive_precision)] -#[allow(clippy::unreadable_literal)] mod qdm2; const QT_CODECS: &[DecoderInfo] = &[ diff --git a/nihav-qt/src/codecs/qdm2qmf.rs b/nihav-qt/src/codecs/qdm2qmf.rs index d8cafa2..c1f461a 100644 --- a/nihav-qt/src/codecs/qdm2qmf.rs +++ b/nihav-qt/src/codecs/qdm2qmf.rs @@ -421,9 +421,9 @@ unimplemented!(); 16 => { if br.left() >= 10 { if zero_coding { - for i in 0..5 { + for (i, dst) in samples[..5].iter_mut().enumerate() { if idx + i >= 128 { break; } - samples[i] = if br.read_bool() { + *dst = if br.read_bool() { let ix = (br.read(1) as usize) * 2; QUANT_1BIT[jstereo as usize][ix] } else { 0.0 }; @@ -431,9 +431,8 @@ unimplemented!(); } else { let idx = br.read(8) as usize; validate!(idx < self.tables.mod3.len()); - for i in 0..5 { - let k = self.tables.mod3[idx][i] as usize; - samples[i] = QUANT_1BIT[jstereo as usize][k]; + for (dst, &k) in samples.iter_mut().zip(self.tables.mod3[idx].iter()) { + *dst = QUANT_1BIT[jstereo as usize][k as usize]; } } } else { @@ -447,9 +446,8 @@ unimplemented!(); if br.left() >= 7 { let idx = br.read(7) as usize; validate!(idx < self.tables.mod5.len()); - for i in 0..3 { - let k = self.tables.mod5[idx][i] as usize; - samples[i] = ((k as f32) - 2.0) * 0.5; + for (dst, &k) in samples.iter_mut().zip(self.tables.mod5[idx].iter()) { + *dst = ((k as f32) - 2.0) * 0.5; } } else { for el in samples.iter_mut().take(3) { diff --git a/nihav-qt/src/codecs/qdmc.rs b/nihav-qt/src/codecs/qdmc.rs index e80e098..442b9ed 100644 --- a/nihav-qt/src/codecs/qdmc.rs +++ b/nihav-qt/src/codecs/qdmc.rs @@ -105,9 +105,10 @@ impl QdmcDecoder { let next = noise_bands[band + 2]; let noise = &mut self.noise_tab[band]; - for i in prev..cur { - noise[i] = ((i - prev) as f32) / ((cur - prev) as f32); + for (i, el) in noise[prev..cur].iter_mut().enumerate() { + *el = (i as f32) / ((cur - prev) as f32); } + #[allow(clippy::needless_range_loop)] for i in cur..next { noise[i] = ((next - i) as f32) / ((next - cur) as f32); } @@ -196,8 +197,8 @@ impl QdmcDecoder { let start = noise_bands[band]; let end = noise_bands[band + 2].min(self.sf_len); let linscale = &self.noise_tab[band]; - for i in start..end { - self.tmp[i] += scale * linscale[i]; + for (el, &add) in self.tmp[start..end].iter_mut().zip(linscale[start..end].iter()) { + *el += scale * add; } } @@ -210,14 +211,14 @@ impl QdmcDecoder { } } fn add_tones(&mut self, sf: usize, start_idx: &mut [usize; 5]) { - for group in 0..5 { + for (group, group_start) in start_idx.iter_mut().enumerate() { let group_bits = 4 - group; let group_size = (1 << (group_bits + 1)) - 1; - for tone in self.tones[group].iter().skip(start_idx[group]) { + for tone in self.tones[group].iter().skip(*group_start) { if (tone.offset as usize) > sf { break; } - start_idx[group] += 1; + *group_start += 1; let pos = (tone.freq >> group_bits) as usize; let scale = SCALES[(tone.amp_idx & 0x3F) as usize] / 32768.0; diff --git a/nihav-qt/src/codecs/qdmcommon.rs b/nihav-qt/src/codecs/qdmcommon.rs index 17ce03f..8721fb0 100644 --- a/nihav-qt/src/codecs/qdmcommon.rs +++ b/nihav-qt/src/codecs/qdmcommon.rs @@ -12,14 +12,13 @@ pub struct QdmBitReader<'a> { } #[allow(clippy::identity_op)] -#[allow(dead_code)] impl<'a> QdmBitReader<'a> { pub fn new(src: &'a [u8]) -> Self { Self{ cache: 0, pos: 0, bits: 0, src } } - pub fn tell(&self) -> usize { + /*pub fn tell(&self) -> usize { self.pos * 8 - (self.bits as usize) - } + }*/ pub fn left(&self) -> isize { ((self.src.len() as isize) - (self.pos as isize)) * 8 + (self.bits as isize) } @@ -87,7 +86,6 @@ impl<'a> QdmBitReader<'a> { } impl<'a, S: Copy> CodebookReader for QdmBitReader<'a> { - #[allow(unused_variables)] fn read_cb(&mut self, cb: &Codebook) -> CodebookResult { let mut esc = true; let mut idx = 0; diff --git a/nihav-qt/src/codecs/rle.rs b/nihav-qt/src/codecs/rle.rs index 1ff1059..d8374c5 100644 --- a/nihav-qt/src/codecs/rle.rs +++ b/nihav-qt/src/codecs/rle.rs @@ -31,19 +31,17 @@ struct RleDecoder { depth: u8, } -#[allow(clippy::needless_range_loop)] fn unpack_mono(src: u16, dst: &mut [u8; 16]) { - for i in 0..16 { - dst[i] = ((src >> (15 - i)) & 1) as u8; + for (i, el) in dst.iter_mut().enumerate() { + *el = ((src >> (15 - i)) & 1) as u8; } } -#[allow(clippy::needless_range_loop)] fn unpack_pixels(src: u32, dst: &mut [u8; 16], depth: u8) { let depth = depth as usize; let mask = (1 << depth) - 1; - for i in 0..32 / depth { - dst[i] = ((src >> (32 - depth - i * depth)) & mask) as u8; + for (i, el) in dst[..32 / depth].iter_mut().enumerate() { + *el = ((src >> (32 - depth - i * depth)) & mask) as u8; } } diff --git a/nihav-qt/src/codecs/svq1.rs b/nihav-qt/src/codecs/svq1.rs index f01c80f..1fd52e3 100644 --- a/nihav-qt/src/codecs/svq1.rs +++ b/nihav-qt/src/codecs/svq1.rs @@ -130,17 +130,16 @@ struct SVQ1Decoder { } impl SVQ1Decoder { - #[allow(clippy::needless_range_loop)] fn new() -> Self { let mut intra_stages_cb = Vec::with_capacity(6); - for i in 0..6 { - let mut cbd = SVQ1DescReader { table: &SVQ_INTRA_STAGE_CODES[i], bias: -1 }; + for table in SVQ_INTRA_STAGE_CODES.iter() { + let mut cbd = SVQ1DescReader { table, bias: -1 }; let cb = Codebook::new(&mut cbd, CodebookMode::MSB).unwrap(); intra_stages_cb.push(cb); } let mut inter_stages_cb = Vec::with_capacity(6); - for i in 0..6 { - let mut cbd = SVQ1DescReader { table: &SVQ_INTER_STAGE_CODES[i], bias: -1 }; + for table in SVQ_INTER_STAGE_CODES.iter() { + let mut cbd = SVQ1DescReader { table, bias: -1 }; let cb = Codebook::new(&mut cbd, CodebookMode::MSB).unwrap(); inter_stages_cb.push(cb); } @@ -392,7 +391,7 @@ impl NADecoder for SVQ1Decoder { Err(DecoderError::InvalidData) } } - #[allow(clippy::collapsible_if)] + #[allow(clippy::collapsible_else_if)] fn decode(&mut self, supp: &mut NADecoderSupport, pkt: &NAPacket) -> DecoderResult { let src = pkt.get_buffer(); validate!(src.len() >= 2); diff --git a/nihav-qt/src/codecs/svq3.rs b/nihav-qt/src/codecs/svq3.rs index 1a87ca6..9951cd2 100644 --- a/nihav-qt/src/codecs/svq3.rs +++ b/nihav-qt/src/codecs/svq3.rs @@ -316,12 +316,10 @@ fn decode_chroma_dc(br: &mut BitReader) -> DecoderResult<[i16; 4]> { if val == 0 { break; } let sign = (val & 1) == 0; let val = (val + 1) >> 1; - let (run, level) = if val < 3 { - (0, val as i16) - } else if val == 3 { - (1, 1) - } else { - ((val & 3) as usize, (((val + 9) >> 2) - (val & 3)) as i16) + let (run, level) = match val { + 0..=2 => (0, val as i16), + 3 => (1, 1), + _ => ((val & 3) as usize, (((val + 9) >> 2) - (val & 3)) as i16) }; idx += run; validate!(idx < blk.len()); @@ -647,11 +645,11 @@ unimplemented!(); } } } - for comp in 0..2 { - for i in 0..4 { + for (comp, cdcs) in cdcs.iter().enumerate() { + for (i, &c_dc) in cdcs.iter().enumerate() { let blk_idx = 16 + comp * 4 + i; - self.coeffs[blk_idx][0] = cdcs[comp][i]; - self.dc_only[blk_idx] = cdcs[comp][i] != 0; + self.coeffs[blk_idx][0] = c_dc; + self.dc_only[blk_idx] = c_dc != 0; idct(&mut self.coeffs[blk_idx], SVQ3_CHROMA_QUANT[sstate.q as usize], true); } } @@ -659,6 +657,7 @@ unimplemented!(); Ok(()) } + #[allow(clippy::identity_op)] fn do_mc_p(&mut self, br: &mut BitReader, mb_type: usize, sstate: &mut SState, dframe: &mut NASimpleVideoFrame) -> DecoderResult<()> { if mb_type == 0 { self.mvi.fill(self.mb_x, self.mb_y, true, ZERO_MV); @@ -885,11 +884,11 @@ unimplemented!(); } } } - for comp in 0..2 { - for i in 0..4 { + for (comp, cdcs) in cdcs.iter().enumerate() { + for (i, &c_dc) in cdcs.iter().enumerate() { let blk_idx = 16 + comp * 4 + i; - self.coeffs[blk_idx][0] = cdcs[comp][i]; - self.dc_only[blk_idx] = cdcs[comp][i] != 0; + self.coeffs[blk_idx][0] = c_dc; + self.dc_only[blk_idx] = c_dc != 0; idct(&mut self.coeffs[blk_idx], SVQ3_CHROMA_QUANT[sstate.q as usize], true); } } @@ -966,6 +965,7 @@ unimplemented!(); } } } + #[allow(clippy::field_reassign_with_default)] fn decode_slice(&mut self, br: &mut BitReader, hdr: &SVQ3Header, dframe: &mut NASimpleVideoFrame) -> DecoderResult<()> { let mut mb_idx = self.mb_x + self.mb_y * self.mb_w; let mbs = self.mb_w * self.mb_h; @@ -987,10 +987,8 @@ unimplemented!(); sstate.has_tr = false; } - if br.left() < 8 { - if (br.tell() & 7) == 0 && br.peek(8) == 0 { - return Ok(()); - } + if br.left() < 8 && (br.tell() & 7) == 0 && br.peek(8) == 0 { + return Ok(()); } let mut mb_type = br.read_code(UintCodeType::Gamma)? as usize; if hdr.ftype == FrameType::I { diff --git a/nihav-qt/src/codecs/svq3dsp.rs b/nihav-qt/src/codecs/svq3dsp.rs index 0c45402..b97ea16 100644 --- a/nihav-qt/src/codecs/svq3dsp.rs +++ b/nihav-qt/src/codecs/svq3dsp.rs @@ -1,6 +1,5 @@ use nihav_codec_support::codecs::blockdsp::*; -#[allow(dead_code)] #[derive(Debug,Clone,Copy)] pub enum PredType4x4 { Ver, @@ -17,7 +16,6 @@ pub enum PredType4x4 { DC128, } -#[allow(dead_code)] #[derive(Debug,Clone,Copy)] pub enum PredType8x8 { DC, diff --git a/nihav-qt/src/lib.rs b/nihav-qt/src/lib.rs index 59c415c..712dd86 100644 --- a/nihav-qt/src/lib.rs +++ b/nihav-qt/src/lib.rs @@ -2,10 +2,7 @@ extern crate nihav_core; extern crate nihav_codec_support; -#[allow(clippy::comparison_chain)] #[allow(clippy::single_match)] -#[allow(clippy::field_reassign_with_default)] #[allow(clippy::upper_case_acronyms)] -#[allow(clippy::collapsible_else_if)] mod codecs; pub use crate::codecs::qt_register_all_decoders;