From 7e6086e50dce8780e59c8d9c0d2d74aa25aaae9e Mon Sep 17 00:00:00 2001 From: Kostya Shishkov Date: Wed, 15 May 2019 13:27:33 +0200 Subject: [PATCH] rad: fix some clippy warnings --- nihav-rad/src/codecs/bink2.rs | 8 +++----- nihav-rad/src/codecs/binkaud.rs | 2 +- nihav-rad/src/codecs/binkvid.rs | 14 +++++--------- nihav-rad/src/codecs/mod.rs | 2 +- nihav-rad/src/codecs/smacker.rs | 4 +--- nihav-rad/src/demuxers/bink.rs | 5 ++--- nihav-rad/src/demuxers/mod.rs | 4 ++-- nihav-rad/src/demuxers/smacker.rs | 2 +- nihav-rad/src/lib.rs | 9 +++++++++ 9 files changed, 25 insertions(+), 25 deletions(-) diff --git a/nihav-rad/src/codecs/bink2.rs b/nihav-rad/src/codecs/bink2.rs index eb3158b..8c09478 100644 --- a/nihav-rad/src/codecs/bink2.rs +++ b/nihav-rad/src/codecs/bink2.rs @@ -1713,11 +1713,11 @@ fn decode_cbp_luma_old(br: &mut BitReader, prev_cbp: u32) -> DecoderResult if !br.read_bool()? { nib1 = br.read(4)?; } - new_cbp = new_cbp | (nib1 << 4); + new_cbp |= nib1 << 4; if !br.read_bool()? { nib1 = br.read(4)?; } - new_cbp = new_cbp | (nib1 << 8); + new_cbp |= nib1 << 8; if !br.read_bool()? { nib1 = br.read(4)?; } @@ -1926,9 +1926,7 @@ impl NADecoder for Bink2Decoder { let mut buf; self.key_frame = pkt.is_keyframe(); - let bufret = alloc_video_buffer(self.info.get_properties().get_video_info().unwrap(), 5); - if let Err(_) = bufret { return Err(DecoderError::InvalidData); } - let bufinfo = bufret.unwrap(); + let bufinfo = alloc_video_buffer(self.info.get_properties().get_video_info().unwrap(), 5)?; buf = bufinfo.get_vbuf().unwrap(); self.decode_frame_new(&mut br, &mut buf, pkt.is_keyframe())?; diff --git a/nihav-rad/src/codecs/binkaud.rs b/nihav-rad/src/codecs/binkaud.rs index daae9df..b0c4fc2 100644 --- a/nihav-rad/src/codecs/binkaud.rs +++ b/nihav-rad/src/codecs/binkaud.rs @@ -71,7 +71,7 @@ impl BinkAudioDecoder { transform: Transform::None, version_b: false, len: 0, - quants: quants, + quants, bands: [MAX_BANDS + 1; 26], num_bands: 0, duration: 0, diff --git a/nihav-rad/src/codecs/binkvid.rs b/nihav-rad/src/codecs/binkvid.rs index 0a818cb..69e30fe 100644 --- a/nihav-rad/src/codecs/binkvid.rs +++ b/nihav-rad/src/codecs/binkvid.rs @@ -30,7 +30,7 @@ impl Tree { if br.read_bool()? { let len = br.read(3)? as usize; let mut present: [bool; 16] = [false; 16]; - for i in 0..len+1 { + for i in 0..=len { self.syms[i] = br.read(4)? as u8; present[self.syms[i] as usize] = true; } @@ -44,7 +44,7 @@ impl Tree { let len = br.read(2)? as usize; let mut syms: [u8; 16] = [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]; let mut tmp: [u8; 16] = [0; 16]; - for bits in 0..len+1 { + for bits in 0..=len { let size = 1 << bits; for arr in syms.chunks_mut(size * 2) { let mut ptr0 = 0; @@ -1053,7 +1053,7 @@ fn read_dct_coefficients(br: &mut BitReader, block: &mut [i32; 64], scan: &[usiz let q_index = if let Some(qidx) = q { qidx } else { br.read(4)? as usize }; let qmat = &quant_matrices[q_index]; block[0] = block[0].wrapping_mul(qmat[0]) >> 11; - for idx in coef_idx.into_iter().take(coef_count) { + for idx in coef_idx.iter().take(coef_count) { block[scan[*idx]] = block[scan[*idx]].wrapping_mul(qmat[*idx]) >> 11; } @@ -1218,18 +1218,14 @@ impl NADecoder for BinkDecoder { if let Some(bbuf) = bufret { buf = bbuf; } else { - let bufret = alloc_video_buffer(self.info.get_properties().get_video_info().unwrap(), 4); - if let Err(_) = bufret { return Err(DecoderError::InvalidData); } - let bufinfo = bufret.unwrap(); + let bufinfo = alloc_video_buffer(self.info.get_properties().get_video_info().unwrap(), 4)?; buf = bufinfo.get_vbuf().unwrap(); self.key_frame = true; self.hams.add_frame(buf); buf = self.hams.get_output_frame().unwrap(); } } else { - let bufret = alloc_video_buffer(self.info.get_properties().get_video_info().unwrap(), 4); - if let Err(_) = bufret { return Err(DecoderError::InvalidData); } - let bufinfo = bufret.unwrap(); + let bufinfo = alloc_video_buffer(self.info.get_properties().get_video_info().unwrap(), 4)?; buf = bufinfo.get_vbuf().unwrap(); } diff --git a/nihav-rad/src/codecs/mod.rs b/nihav-rad/src/codecs/mod.rs index 4ce5563..eec8c4c 100644 --- a/nihav-rad/src/codecs/mod.rs +++ b/nihav-rad/src/codecs/mod.rs @@ -29,7 +29,7 @@ const RAD_CODECS: &[DecoderInfo] = &[ ]; pub fn rad_register_all_codecs(rd: &mut RegisteredDecoders) { - for decoder in RAD_CODECS.into_iter() { + for decoder in RAD_CODECS.iter() { rd.add_decoder(decoder.clone()); } } diff --git a/nihav-rad/src/codecs/smacker.rs b/nihav-rad/src/codecs/smacker.rs index 6eefdce..99d40d6 100644 --- a/nihav-rad/src/codecs/smacker.rs +++ b/nihav-rad/src/codecs/smacker.rs @@ -444,9 +444,7 @@ impl NADecoder for SmackerVideoDecoder { if src.len() > PAL_SIZE { let mut br = BitReader::new(&src[PAL_SIZE..], src.len() - PAL_SIZE, BitReaderMode::LE); - let bufret = alloc_video_buffer(self.info.get_properties().get_video_info().unwrap(), 2); - if let Err(_) = bufret { return Err(DecoderError::InvalidData); } - bufinfo = bufret.unwrap(); + bufinfo = alloc_video_buffer(self.info.get_properties().get_video_info().unwrap(), 2)?; let mut buf = bufinfo.get_vbuf().unwrap(); is_intra = self.decode_frame(&mut br)?; self.output_frame(&mut buf); diff --git a/nihav-rad/src/demuxers/bink.rs b/nihav-rad/src/demuxers/bink.rs index 8dfbf64..29427af 100644 --- a/nihav-rad/src/demuxers/bink.rs +++ b/nihav-rad/src/demuxers/bink.rs @@ -68,8 +68,7 @@ impl<'a> DemuxCore<'a> for BinkDemuxer<'a> { validate!((self.frames > 0) && (tb_num > 0) && (tb_den > 0) && (max_size < fsize)); let mut flags: [u8; 4] = [0; 4]; src.read_buf(&mut flags)?; - let mut edata: Vec = Vec::with_capacity(8); - edata.resize(8, 0); + let mut edata: Vec = vec![0; 8]; let p0 = &mut edata[0..4]; p0.copy_from_slice(&magic); let p1 = &mut edata[4..][..4]; @@ -99,7 +98,7 @@ impl<'a> DemuxCore<'a> for BinkDemuxer<'a> { } self.frame_pos = Vec::with_capacity(self.frames + 1); - for _ in 0..self.frames+1 { + for _ in 0..=self.frames { let pos = src.read_u32le()?; self.frame_pos.push(pos); } diff --git a/nihav-rad/src/demuxers/mod.rs b/nihav-rad/src/demuxers/mod.rs index a1234bd..c88fdd6 100644 --- a/nihav-rad/src/demuxers/mod.rs +++ b/nihav-rad/src/demuxers/mod.rs @@ -10,7 +10,7 @@ mod smacker; #[cfg(feature="demuxer_bink")] mod bink; -const RAD_DEMUXERS: &[&'static DemuxerCreator] = &[ +const RAD_DEMUXERS: &[&DemuxerCreator] = &[ #[cfg(feature="demuxer_smk")] &smacker::SMKDemuxerCreator {}, #[cfg(feature="demuxer_bink")] @@ -18,7 +18,7 @@ const RAD_DEMUXERS: &[&'static DemuxerCreator] = &[ ]; pub fn rad_register_all_demuxers(rd: &mut RegisteredDemuxers) { - for demuxer in RAD_DEMUXERS.into_iter() { + for demuxer in RAD_DEMUXERS.iter() { rd.add_demuxer(*demuxer); } } diff --git a/nihav-rad/src/demuxers/smacker.rs b/nihav-rad/src/demuxers/smacker.rs index 6555319..3e612ef 100644 --- a/nihav-rad/src/demuxers/smacker.rs +++ b/nihav-rad/src/demuxers/smacker.rs @@ -178,7 +178,7 @@ impl<'a> DemuxCore<'a> for SmackerVideoDemuxer<'a> { validate!(chunk_size > 0); validate!(payload_size >= chunk_size); payload_size -= chunk_size; - let oldpal = self.pal.clone(); + let oldpal = self.pal; let mut idx = 0; let endpos = self.src.tell() + (chunk_size as u64) - 1; while idx < 256 { diff --git a/nihav-rad/src/lib.rs b/nihav-rad/src/lib.rs index f723e9e..1b566da 100644 --- a/nihav-rad/src/lib.rs +++ b/nihav-rad/src/lib.rs @@ -1,6 +1,15 @@ extern crate nihav_core; #[cfg(feature="decoders")] +#[allow(clippy::cast_lossless)] +#[allow(clippy::collapsible_if)] +#[allow(clippy::excessive_precision)] +#[allow(clippy::identity_op)] +#[allow(clippy::needless_range_loop)] +#[allow(clippy::too_many_arguments)] +#[allow(clippy::unreadable_literal)] +#[allow(clippy::useless_let_if_seq)] pub mod codecs; #[cfg(feature="demuxers")] +#[allow(clippy::cast_lossless)] pub mod demuxers; \ No newline at end of file -- 2.39.5