From: Kostya Shishkov Date: Tue, 16 Jun 2020 10:12:22 +0000 (+0200) Subject: game: fix or silence clippy warnings X-Git-Url: https://git.nihav.org/?p=nihav.git;a=commitdiff_plain;h=7450554d7dbd9ac5bb73bc48389bb9c08dc8d714 game: fix or silence clippy warnings --- diff --git a/nihav-game/src/codecs/bmv3.rs b/nihav-game/src/codecs/bmv3.rs index a9d7f71..cde7892 100644 --- a/nihav-game/src/codecs/bmv3.rs +++ b/nihav-game/src/codecs/bmv3.rs @@ -110,6 +110,7 @@ impl BMV3VideoDecoder { is_intra: false, } } + #[allow(clippy::identity_op)] fn decode_frame(&mut self, br: &mut ByteReader) -> DecoderResult<()> { let mut idx = 0; loop { @@ -532,6 +533,7 @@ impl BMV3AudioDecoder { } } +#[allow(clippy::identity_op)] fn decode_block(mode: u8, src: &[u8], dst: &mut [i16], mut pred: i16) -> i16 { let steps = &BMV_AUDIO_STEPS[mode as usize]; let mut val2 = 0; diff --git a/nihav-game/src/codecs/gremlinvideo.rs b/nihav-game/src/codecs/gremlinvideo.rs index 73f4225..4b53ae8 100644 --- a/nihav-game/src/codecs/gremlinvideo.rs +++ b/nihav-game/src/codecs/gremlinvideo.rs @@ -143,17 +143,17 @@ impl GremlinVideoDecoder { let mut sidx = PREAMBLE_SIZE; let mut didx = 0; - for i in 0..768 { dst[paloff + i] = self.pal[i]; } + dst[paloff..][..768].copy_from_slice(&self.pal); if !self.scale_v && !self.scale_h { for _ in 0..h { - for x in 0..w { dst[didx + x] = self.frame[sidx + x]; } + dst[didx..][..w].copy_from_slice(&self.frame[sidx..][..w]); sidx += w; didx += stride; } } else { for y in 0..h { if !self.scale_v { - for x in 0..w { dst[didx + x] = self.frame[sidx + x]; } + dst[didx..][..w].copy_from_slice(&self.frame[sidx..][..w]); } else { for x in 0..w { dst[didx + x] = self.frame[sidx + x/2]; } } @@ -247,6 +247,7 @@ impl GremlinVideoDecoder { Ok(()) } + #[allow(clippy::identity_op)] fn decode_method68(&mut self, br: &mut ByteReader, skip: usize, use8: bool) -> DecoderResult<()> { let mut bits = Bits32::new(); diff --git a/nihav-game/src/codecs/lhst500f22.rs b/nihav-game/src/codecs/lhst500f22.rs index e3535f5..e795070 100644 --- a/nihav-game/src/codecs/lhst500f22.rs +++ b/nihav-game/src/codecs/lhst500f22.rs @@ -313,6 +313,7 @@ impl LHDecoder { } Ok(()) } + #[allow(clippy::identity_op)] fn unpack_samples(&mut self, br: &mut BitReader) -> DecoderResult<()> { for grp in 0..3 { for gr in 0..4 { @@ -368,7 +369,7 @@ impl NADecoder for LHDecoder { fn init(&mut self, _supp: &mut NADecoderSupport, info: NACodecInfoRef) -> DecoderResult<()> { if let NACodecTypeInfo::Audio(ainfo) = info.get_properties() { self.ainfo = NAAudioInfo::new(ainfo.get_sample_rate(), 1, SND_F32P_FORMAT, CODEC_SAMPLES); - self.info = info.replace_info(NACodecTypeInfo::Audio(self.ainfo.clone())); + self.info = info.replace_info(NACodecTypeInfo::Audio(self.ainfo)); self.chmap = NAChannelMap::from_str("C").unwrap(); Ok(()) } else { diff --git a/nihav-game/src/codecs/midivid.rs b/nihav-game/src/codecs/midivid.rs index 74ec75f..611ca60 100644 --- a/nihav-game/src/codecs/midivid.rs +++ b/nihav-game/src/codecs/midivid.rs @@ -22,10 +22,10 @@ fn lz_decompress(src: &[u8], dst: &mut [u8]) -> DecoderResult<()> { let mut dpos = 0; let end = src.len(); while spos < end { - let oplo = src[spos] as u16; + let oplo = u16::from(src[spos]); spos += 1; if spos >= end { return Err(DecoderError::ShortData); } - let ophi = src[spos] as u16; + let ophi = u16::from(src[spos]); spos += 1; let mut op = (ophi << 8) | oplo; for _ in 0..16 { @@ -58,6 +58,7 @@ fn lz_decompress(src: &[u8], dst: &mut [u8]) -> DecoderResult<()> { Ok(()) } +#[allow(clippy::identity_op)] fn decode_frame(frm: &mut NASimpleVideoFrame, src: &[u8], width: usize, height: usize) -> DecoderResult { validate!(src.len() > 8); let num_vec = read_u16le(&src[0..])? as usize; diff --git a/nihav-game/src/codecs/midivid3.rs b/nihav-game/src/codecs/midivid3.rs index 7ffb045..3a3c161 100644 --- a/nihav-game/src/codecs/midivid3.rs +++ b/nihav-game/src/codecs/midivid3.rs @@ -297,11 +297,11 @@ fn decode_values(br: &mut BitReader, dst: &mut [i16], cb: &Codebook) -> Dec } fn dequant(val: i16, q: i16) -> i32 { - (val as i32) * (q as i32) + i32::from(val) * i32::from(q) } fn scale_coef(val: i32, scale: i16) -> i32 { - ((val as i32) * (scale as i32)) >> 8 + (val * i32::from(scale)) >> 8 } macro_rules! idct_1d { @@ -334,6 +334,8 @@ macro_rules! idct_1d { } } +#[allow(clippy::erasing_op)] +#[allow(clippy::identity_op)] fn idct(blk: &mut [i32; 64]) { for i in 0..8 { idct_1d!(blk[i + 0 * 8], blk[i + 1 * 8], blk[i + 2 * 8], blk[i + 3 * 8], @@ -343,7 +345,7 @@ fn idct(blk: &mut [i32; 64]) { idct_1d!(row[0], row[1], row[2], row[3], row[4], row[5], row[6], row[7]); } for el in blk.iter_mut() { - *el = *el >> 5; + *el >>= 5; } } @@ -394,7 +396,7 @@ fn decode_block_inter(dst: &mut [u8], stride: usize, btype: usize, coeffs: &[i16 let dc = dequant(coeffs[0], qmat[0]) >> 5; for line in dst.chunks_mut(stride).take(8) { for el in line.iter_mut().take(8) { - *el = ((*el as i32) + dc).max(0).min(255) as u8; + *el = (i32::from(*el) + dc).max(0).min(255) as u8; } } }, @@ -407,7 +409,7 @@ fn decode_block_inter(dst: &mut [u8], stride: usize, btype: usize, coeffs: &[i16 idct(&mut blk); for (line, row) in dst.chunks_mut(stride).zip(blk.chunks(8)).take(8) { for (dst, coef) in line.iter_mut().zip(row.iter()).take(8) { - *dst = (*dst as i32 + *coef).max(0).min(255) as u8; + *dst = (i32::from(*dst) + *coef).max(0).min(255) as u8; } } }, @@ -419,7 +421,7 @@ fn decode_block_inter(dst: &mut [u8], stride: usize, btype: usize, coeffs: &[i16 idct(&mut blk); for (line, row) in dst.chunks_mut(stride).zip(blk.chunks(8)).take(8) { for (dst, coef) in line.iter_mut().zip(row.iter()).take(8) { - *dst = (*dst as i32 + *coef).max(0).min(255) as u8; + *dst = (i32::from(*dst) + *coef).max(0).min(255) as u8; } } }, @@ -428,13 +430,13 @@ fn decode_block_inter(dst: &mut [u8], stride: usize, btype: usize, coeffs: &[i16 fn init_quant(qmat: &mut [i16; 64], base_qmat: &[u8; 64], quant: u8) { let q = if quant < 50 { - 5000 / (quant.max(1) as i32) + 5000 / i32::from(quant.max(1)) } else { - ((100 - quant.min(100)) * 2) as i32 + i32::from((100 - quant.min(100)) * 2) }; for (inq, (outq, scale)) in base_qmat.iter().zip(qmat.iter_mut().zip(QUANT_MATRIX.iter())) { - let val = (((*inq as i32) * q + 50) / 100).max(1).min(0x7FFF); - *outq = ((val * (*scale as i32) + 0x800) >> 12) as i16; + let val = ((i32::from(*inq) * q + 50) / 100).max(1).min(0x7FFF); + *outq = ((val * i32::from(*scale) + 0x800) >> 12) as i16; } } diff --git a/nihav-game/src/codecs/vmd.rs b/nihav-game/src/codecs/vmd.rs index 939dcd6..110548a 100644 --- a/nihav-game/src/codecs/vmd.rs +++ b/nihav-game/src/codecs/vmd.rs @@ -451,7 +451,7 @@ impl NADecoder for VMDAudioDecoder { let edata = info.get_extradata(); let flags = if let Some(ref buf) = edata { validate!(buf.len() >= 2); - (buf[0] as u16) | ((buf[1] as u16) << 8) + u16::from(buf[0]) | (u16::from(buf[1]) << 8) } else { 0 }; @@ -480,13 +480,15 @@ impl NADecoder for VMDAudioDecoder { } }; self.ainfo = NAAudioInfo::new(ainfo.get_sample_rate(), ainfo.get_channels(), fmt, ainfo.get_block_len()); - self.info = info.replace_info(NACodecTypeInfo::Audio(self.ainfo.clone())); + self.info = info.replace_info(NACodecTypeInfo::Audio(self.ainfo)); self.chmap = NAChannelMap::from_str(if channels == 1 { "C" } else { "L,R" }).unwrap(); Ok(()) } else { Err(DecoderError::InvalidData) } } + #[allow(clippy::identity_op)] + #[allow(clippy::cyclomatic_complexity)] fn decode(&mut self, _supp: &mut NADecoderSupport, pkt: &NAPacket) -> DecoderResult { let info = pkt.get_stream().get_info(); if let NACodecTypeInfo::Audio(_) = info.get_properties() { diff --git a/nihav-game/src/demuxers/bmv.rs b/nihav-game/src/demuxers/bmv.rs index 19019d4..fafd6f0 100644 --- a/nihav-game/src/demuxers/bmv.rs +++ b/nihav-game/src/demuxers/bmv.rs @@ -116,6 +116,7 @@ struct BMV3Demuxer<'a> { impl<'a> DemuxCore<'a> for BMV3Demuxer<'a> { #[allow(unused_variables)] + #[allow(clippy::cast_lossless)] fn open(&mut self, strmgr: &mut StreamManager, _seek_index: &mut SeekIndex) -> DemuxerResult<()> { let src = &mut self.src; diff --git a/nihav-game/src/demuxers/vmd.rs b/nihav-game/src/demuxers/vmd.rs index c6da8f4..3c6e152 100644 --- a/nihav-game/src/demuxers/vmd.rs +++ b/nihav-game/src/demuxers/vmd.rs @@ -160,7 +160,7 @@ impl<'a> DemuxCore<'a> for VMDDemuxer<'a> { let is_video = cur_frame.chtype == CHTYPE_VIDEO; let mut buf: Vec = Vec::with_capacity(FRAME_HDR_SIZE + (cur_frame.size as usize)); - if !(is_video && self.is_indeo) && !(!is_video && self.is_lhaud) { + if !((is_video && self.is_indeo) || (!is_video && self.is_lhaud)) { buf.extend_from_slice(&cur_frame.hdr); buf.resize(FRAME_HDR_SIZE + (cur_frame.size as usize), 0); self.src.read_buf(&mut buf[FRAME_HDR_SIZE..])?; diff --git a/nihav-game/src/lib.rs b/nihav-game/src/lib.rs index f2a94f9..f619cb9 100644 --- a/nihav-game/src/lib.rs +++ b/nihav-game/src/lib.rs @@ -1,7 +1,15 @@ extern crate nihav_core; extern crate nihav_codec_support; +#[allow(clippy::collapsible_if)] +#[allow(clippy::excessive_precision)] +#[allow(clippy::needless_range_loop)] +#[allow(clippy::unreadable_literal)] +#[allow(clippy::useless_let_if_seq)] mod codecs; pub use crate::codecs::game_register_all_codecs; +#[allow(clippy::collapsible_if)] +#[allow(clippy::needless_range_loop)] +#[allow(clippy::unreadable_literal)] mod demuxers; -pub use crate::demuxers::game_register_all_demuxers; \ No newline at end of file +pub use crate::demuxers::game_register_all_demuxers;