From: Kostya Shishkov Date: Fri, 8 Nov 2024 19:19:18 +0000 (+0100) Subject: nihav_vivo: fix or update clippy warnings X-Git-Url: https://git.nihav.org/?a=commitdiff_plain;h=8dc6faae6514fd370d0cf2de5dd44aaf9a6d74ff;p=nihav.git nihav_vivo: fix or update clippy warnings --- diff --git a/nihav-vivo/src/codecs/g723_1.rs b/nihav-vivo/src/codecs/g723_1.rs index 89d694d..3cfe3b7 100644 --- a/nihav-vivo/src/codecs/g723_1.rs +++ b/nihav-vivo/src/codecs/g723_1.rs @@ -404,9 +404,9 @@ impl G7231Decoder { for (i, subframe) in self.subframe.iter_mut().enumerate() { subframe.gen_fcb_excitation(&mut self.excitation[exc_start..], self.is_6300, FCB_MAX_POS[i], if (i & 1) == 0 { 6 } else { 5 }); subframe.gen_acb_excitation(&mut acb_vector, &self.excitation[SUBFRAME_LEN * i..], self.is_6300); - for i in 0..SUBFRAME_LEN { - let val = self.excitation[exc_start + i]; - self.excitation[exc_start + i] = val.saturating_add(val).saturating_add(acb_vector[i]); + for (exc, &acb) in self.excitation[exc_start..][..SUBFRAME_LEN].iter_mut() + .zip(acb_vector.iter()) { + *exc = exc.saturating_add(*exc).saturating_add(acb); } exc_start += SUBFRAME_LEN; } @@ -538,7 +538,7 @@ impl G7231Decoder { subframe.acb_lag = ADAPTIVE_LAG[i]; } - let mut off = [0; 4]; + let mut off = [0; SUBFRAMES]; let mut signs = [[0; 11]; 2]; for i in (0..4).step_by(2) { let t = self.cng_rnd.next_range(1 << 13); @@ -552,11 +552,11 @@ impl G7231Decoder { let mut pos = [0; 11 * SUBFRAMES]; let mut pidx = 0; let mut tmp = [0; SUBFRAME_LEN / 2]; - for i in 0..SUBFRAMES { + for (i, &offset) in off.iter().enumerate() { let npulses = if (i & 1) == 0 { 6 } else { 5 }; for j in 0..npulses { let idx = self.cng_rnd.next_range(SUBFRAME_LEN / 2 - j); - pos[pidx] = tmp[idx] * 2 + off[i]; + pos[pidx] = tmp[idx] * 2 + offset; pidx += 1; tmp[idx] = tmp[SUBFRAME_LEN / 2 - 1 - j]; } @@ -572,10 +572,7 @@ impl G7231Decoder { self.subframe[i + 1].gen_acb_excitation(&mut acb_vec, &buf[SUBFRAME_LEN..], self.is_6300); buf[SUBFRAME_LEN..][..SUBFRAME_LEN].copy_from_slice(&acb_vec); - let mut max = 0; - for j in 0..SUBFRAME_LEN*2 { - max |= i32::from(buf[j]).abs(); - } + let max = buf[..SUBFRAME_LEN * 2].iter().fold(0i32, |acc, &a| acc | i32::from(a).abs()); let shift = if max == 0 { 0 } else { (-10 + (32 - max.min(0x7FFF).leading_zeros()) as i32).max(-2) }; @@ -830,8 +827,8 @@ impl G7231Decoder { } fn gain_scale(pf_gain: &mut i32, buf: &mut [i16], energy: i32) { let mut den = 0i32; - for i in 0..SUBFRAME_LEN { - let val = i32::from(buf[i] >> 2); + for &samp in buf[..SUBFRAME_LEN].iter() { + let val = i32::from(samp >> 2); den = den.saturating_add(val * val).saturating_add(val * val); } let mut num = energy; @@ -848,9 +845,9 @@ impl G7231Decoder { gain = 1 << 12; } - for i in 0..SUBFRAME_LEN { + for val in buf[..SUBFRAME_LEN].iter_mut() { *pf_gain = (15 * *pf_gain + gain + (1 << 3)) >> 4; - buf[i] = clip16((i32::from(buf[i]) * (*pf_gain + (*pf_gain >> 4)) + (1 << 10)) >> 11); + *val = clip16((i32::from(*val) * (*pf_gain + (*pf_gain >> 4)) + (1 << 10)) >> 11); } } } diff --git a/nihav-vivo/src/codecs/mod.rs b/nihav-vivo/src/codecs/mod.rs index e869c8d..606e9e7 100644 --- a/nihav-vivo/src/codecs/mod.rs +++ b/nihav-vivo/src/codecs/mod.rs @@ -11,16 +11,11 @@ macro_rules! validate { } #[cfg(any(feature="decoder_vivo1", feature="decoder_vivo2"))] -#[allow(clippy::useless_let_if_seq)] mod vivo; #[cfg(feature="decoder_g723_1")] -#[allow(clippy::needless_range_loop)] -#[allow(clippy::unreadable_literal)] -#[allow(clippy::useless_let_if_seq)] mod g723_1; #[cfg(feature="decoder_siren")] #[allow(clippy::approx_constant)] -#[allow(clippy::needless_range_loop)] mod siren; const VIVO_CODECS: &[DecoderInfo] = &[ diff --git a/nihav-vivo/src/codecs/siren.rs b/nihav-vivo/src/codecs/siren.rs index d026ff3..d342898 100644 --- a/nihav-vivo/src/codecs/siren.rs +++ b/nihav-vivo/src/codecs/siren.rs @@ -92,8 +92,8 @@ impl SirenDecoder { generate_window(WindowType::Sine, 1.0 / 320.0 / 64.0, SAMPLES, true, &mut window); let mut quant_tab = [0.0; 64]; - for i in 0..64 { - quant_tab[i] = 2.0f32.powf((((i as i32) - 24) as f32) / 2.0); + for (i, quant) in quant_tab.iter_mut().enumerate() { + *quant = 2.0f32.powf((((i as i32) - 24) as f32) / 2.0); } SirenDecoder { @@ -185,9 +185,10 @@ impl SirenDecoder { } else { let mut min_value = 99; let mut max_idx = 0; - for reg in 0..NUM_REGIONS { - if max_rate_cat[reg] == 0 { continue; } - let val = offset - self.pow_index[reg] - 2 * (max_rate_cat[reg] as i32); + for (reg, (&max_rate, &pow_index)) in max_rate_cat.iter() + .zip(self.pow_index.iter()).enumerate() { + if max_rate == 0 { continue; } + let val = offset - pow_index - 2 * (max_rate as i32); if min_value > val { min_value = val; max_idx = reg; diff --git a/nihav-vivo/src/codecs/vivo.rs b/nihav-vivo/src/codecs/vivo.rs index 2e73b3b..2b44a2e 100644 --- a/nihav-vivo/src/codecs/vivo.rs +++ b/nihav-vivo/src/codecs/vivo.rs @@ -10,7 +10,6 @@ use nihav_codec_support::codecs::h263::code::*; use nihav_codec_support::codecs::h263::decoder::*; use nihav_codec_support::codecs::h263::data::*; -#[allow(dead_code)] struct Tables { intra_mcbpc_cb: Codebook, inter_mcbpc_cb: Codebook, @@ -401,8 +400,6 @@ fn decode_b_info(br: &mut BitReader, is_pb: bool, is_ipb: bool, is_intra: bool) impl<'a> BlockDecoder for VivoBR<'a> { -#[allow(unused_variables)] -#[allow(clippy::unreadable_literal)] fn decode_pichdr(&mut self) -> DecoderResult { let br = &mut self.br; let syncw = br.read(22)?; @@ -456,14 +453,11 @@ impl<'a> BlockDecoder for VivoBR<'a> { let cpm = br.read_bool()?; validate!(!cpm); - let pbinfo; - if self.is_pb { - let trb = br.read(3)?; - let dbquant = br.read(2)?; - pbinfo = Some(PBInfo::new(trb as u8, dbquant as u8, pbplus)); - } else { - pbinfo = None; - } + let pbinfo = if self.is_pb { + let trb = br.read(3)?; + let dbquant = br.read(2)?; + Some(PBInfo::new(trb as u8, dbquant as u8, pbplus)) + } else { None }; while br.read_bool()? { // skip PEI br.read(8)?; } @@ -478,21 +472,19 @@ impl<'a> BlockDecoder for VivoBR<'a> { Ok(picinfo) } - #[allow(unused_variables)] - fn decode_slice_header(&mut self, info: &PicInfo) -> DecoderResult { + fn decode_slice_header(&mut self, _info: &PicInfo) -> DecoderResult { let br = &mut self.br; let gbsc = br.read(17)?; validate!(gbsc == 1); - let gn = br.read(5)?; - let gfid = br.read(2)?; + let _gn = br.read(5)?; + let _gfid = br.read(2)?; let gquant = br.read(5)?; let ret = SliceInfo::new_gob(0, self.gob_no, gquant as u8); self.gob_no += 1; Ok(ret) } - #[allow(unused_variables)] - fn decode_block_header(&mut self, info: &PicInfo, slice: &SliceInfo, sstate: &SliceState) -> DecoderResult { + fn decode_block_header(&mut self, info: &PicInfo, slice: &SliceInfo, _sstate: &SliceState) -> DecoderResult { let br = &mut self.br; let mut q = slice.get_quant(); match info.get_mode() { @@ -596,13 +588,11 @@ impl<'a> BlockDecoder for VivoBR<'a> { } } - #[allow(unused_variables)] fn decode_block_intra(&mut self, info: &BlockInfo, _sstate: &SliceState, quant: u8, no: usize, coded: bool, blk: &mut [i16; 64]) -> DecoderResult<()> { self.decode_block(quant, true, coded, blk, if no < 4 { 0 } else { no - 3 }, info.get_acpred()) } - #[allow(unused_variables)] - fn decode_block_inter(&mut self, info: &BlockInfo, _sstate: &SliceState, quant: u8, no: usize, coded: bool, blk: &mut [i16; 64]) -> DecoderResult<()> { + fn decode_block_inter(&mut self, _info: &BlockInfo, _sstate: &SliceState, quant: u8, no: usize, coded: bool, blk: &mut [i16; 64]) -> DecoderResult<()> { self.decode_block(quant, false, coded, blk, if no < 4 { 0 } else { no - 3 }, ACPredMode::None) } diff --git a/nihav-vivo/src/lib.rs b/nihav-vivo/src/lib.rs index 469babe..c07172d 100644 --- a/nihav-vivo/src/lib.rs +++ b/nihav-vivo/src/lib.rs @@ -3,7 +3,6 @@ extern crate nihav_core; extern crate nihav_codec_support; #[allow(clippy::upper_case_acronyms)] -#[allow(clippy::needless_late_init)] mod codecs; mod demuxers;