Skip to content

Commit 269cd7d

Browse files
authored
Merge pull request #270 from taavit/clippy-fixes-p1
Basic clippy fixes.
2 parents 509ec66 + bc736a6 commit 269cd7d

File tree

9 files changed

+49
-43
lines changed

9 files changed

+49
-43
lines changed

src/arch/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use std::is_x86_feature_detected;
99

1010
/// Arch-specific implementation of YCbCr conversion. Returns the number of pixels that were
1111
/// converted.
12+
#[allow(clippy::type_complexity)]
1213
pub fn get_color_convert_line_ycbcr() -> Option<unsafe fn(&[u8], &[u8], &[u8], &mut [u8]) -> usize>
1314
{
1415
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
@@ -32,6 +33,7 @@ pub fn get_color_convert_line_ycbcr() -> Option<unsafe fn(&[u8], &[u8], &[u8], &
3233
}
3334

3435
/// Arch-specific implementation of 8x8 IDCT.
36+
#[allow(clippy::type_complexity)]
3537
pub fn get_dequantize_and_idct_block_8x8(
3638
) -> Option<unsafe fn(&[i16; 64], &[u16; 64], usize, &mut [u8])> {
3739
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]

src/arch/ssse3.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,8 @@ pub unsafe fn dequantize_and_idct_block_8x8(
148148

149149
// Read the DCT coefficients, scale them up and dequantize them.
150150
let mut data = [_mm_setzero_si128(); 8];
151-
for i in 0..8 {
152-
data[i] = _mm_slli_epi16(
151+
for (i, item) in data.iter_mut().enumerate() {
152+
*item = _mm_slli_epi16(
153153
_mm_mullo_epi16(
154154
_mm_loadu_si128(coefficients.as_ptr().wrapping_add(i * 8) as *const _),
155155
_mm_loadu_si128(quantization_table.as_ptr().wrapping_add(i * 8) as *const _),
@@ -164,7 +164,7 @@ pub unsafe fn dequantize_and_idct_block_8x8(
164164
idct8(&mut data);
165165
transpose8(&mut data);
166166

167-
for i in 0..8 {
167+
for (i, item) in data.iter_mut().enumerate() {
168168
let mut buf = [0u8; 16];
169169
// The two passes of the IDCT algorithm give us a factor of 8, so the shift here is
170170
// increased by 3.
@@ -174,7 +174,7 @@ pub unsafe fn dequantize_and_idct_block_8x8(
174174
// We want rounding right shift, so we should add (1/2) << (SHIFT+3) before shifting.
175175
const ROUNDING_BIAS: i16 = (1 << (SHIFT + 3)) >> 1;
176176

177-
let data_with_offset = _mm_adds_epi16(data[i], _mm_set1_epi16(OFFSET + ROUNDING_BIAS));
177+
let data_with_offset = _mm_adds_epi16(*item, _mm_set1_epi16(OFFSET + ROUNDING_BIAS));
178178

179179
_mm_storeu_si128(
180180
buf.as_mut_ptr() as *mut _,

src/decoder.rs

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ pub const MAX_COMPONENTS: usize = 4;
2424
mod lossless;
2525
use self::lossless::compute_image_lossless;
2626

27-
#[cfg_attr(rustfmt, rustfmt_skip)]
27+
#[rustfmt::skip]
2828
static UNZIGZAG: [u8; 64] = [
2929
0, 1, 8, 16, 9, 2, 3, 10,
3030
17, 24, 32, 25, 18, 11, 4, 5,
@@ -595,7 +595,7 @@ impl<R: Read> Decoder<R> {
595595
}
596596

597597
let frame = self.frame.as_ref().unwrap();
598-
let preference = Self::select_worker(&frame, PreferWorkerKind::Multithreaded);
598+
let preference = Self::select_worker(frame, PreferWorkerKind::Multithreaded);
599599

600600
worker_scope.get_or_init_worker(preference, |worker| {
601601
self.decode_planes(worker, planes, planes_u16)
@@ -616,14 +616,13 @@ impl<R: Read> Decoder<R> {
616616

617617
let frame = self.frame.as_ref().unwrap();
618618

619-
if {
620-
let required_mem = frame
621-
.components
622-
.len()
623-
.checked_mul(frame.output_size.width.into())
624-
.and_then(|m| m.checked_mul(frame.output_size.height.into()));
625-
required_mem.map_or(true, |m| self.decoding_buffer_size_limit < m)
626-
} {
619+
if frame
620+
.components
621+
.len()
622+
.checked_mul(frame.output_size.width.into())
623+
.and_then(|m| m.checked_mul(frame.output_size.height.into()))
624+
.map_or(true, |m| self.decoding_buffer_size_limit < m)
625+
{
627626
return Err(Error::Format(
628627
"size of decoded image exceeds maximum allowed size".to_owned(),
629628
));
@@ -779,6 +778,7 @@ impl<R: Read> Decoder<R> {
779778
}
780779
}
781780

781+
#[allow(clippy::type_complexity)]
782782
fn decode_scan(
783783
&mut self,
784784
frame: &FrameInfo,
@@ -1009,10 +1009,11 @@ impl<R: Read> Decoder<R> {
10091009
// In the event of non-interleaved streams, if we're still building the buffer out,
10101010
// keep going; don't send it yet. We also need to ensure we don't skip over the last
10111011
// row(s) of the image.
1012-
if !is_interleaved && (mcu_y + 1) * 8 < frame.image_size.height {
1013-
if (mcu_y + 1) % component.vertical_sampling_factor as u16 > 0 {
1014-
continue;
1015-
}
1012+
if !is_interleaved
1013+
&& (mcu_y + 1) * 8 < frame.image_size.height
1014+
&& (mcu_y + 1) % component.vertical_sampling_factor as u16 > 0
1015+
{
1016+
continue;
10161017
}
10171018

10181019
let coefficients_per_mcu_row = component.block_size.width as usize
@@ -1069,6 +1070,7 @@ impl<R: Read> Decoder<R> {
10691070
}
10701071
}
10711072

1073+
#[allow(clippy::too_many_arguments)]
10721074
fn decode_block<R: Read>(
10731075
reader: &mut R,
10741076
coefficients: &mut [i16; 64],
@@ -1321,6 +1323,7 @@ fn compute_image(
13211323
}
13221324
}
13231325

1326+
#[allow(clippy::type_complexity)]
13241327
pub(crate) fn choose_color_convert_func(
13251328
component_count: usize,
13261329
color_transform: ColorTransform,

src/decoder/lossless.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
use std::io::Read;
21
use crate::decoder::{Decoder, MAX_COMPONENTS};
32
use crate::error::{Error, Result};
43
use crate::huffman::HuffmanDecoder;
54
use crate::marker::Marker;
65
use crate::parser::Predictor;
76
use crate::parser::{Component, FrameInfo, ScanInfo};
7+
use std::io::Read;
88

99
impl<R: Read> Decoder<R> {
1010
/// decode_scan_lossless
@@ -185,6 +185,7 @@ impl<R: Read> Decoder<R> {
185185
}
186186

187187
/// H.1.2.1
188+
#[allow(clippy::too_many_arguments)]
188189
fn predict(
189190
ra: i32,
190191
rb: i32,

src/idct.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -579,7 +579,7 @@ fn stbi_fsh(x: Wrapping<i32>) -> Wrapping<i32> {
579579

580580
#[test]
581581
fn test_dequantize_and_idct_block_8x8() {
582-
#[cfg_attr(rustfmt, rustfmt_skip)]
582+
#[rustfmt::skip]
583583
let coefficients: [i16; 8 * 8] = [
584584
-14, -39, 58, -2, 3, 3, 0, 1,
585585
11, 27, 4, -3, 3, 0, 1, 0,
@@ -591,7 +591,7 @@ fn test_dequantize_and_idct_block_8x8() {
591591
0, 0, 0, 0, 0, 0, 0, 0
592592
];
593593

594-
#[cfg_attr(rustfmt, rustfmt_skip)]
594+
#[rustfmt::skip]
595595
let quantization_table: [u16; 8 * 8] = [
596596
8, 6, 5, 8, 12, 20, 26, 31,
597597
6, 6, 7, 10, 13, 29, 30, 28,
@@ -610,7 +610,7 @@ fn test_dequantize_and_idct_block_8x8() {
610610
output_linestride,
611611
&mut output,
612612
);
613-
#[cfg_attr(rustfmt, rustfmt_skip)]
613+
#[rustfmt::skip]
614614
let expected_output = [
615615
118, 92, 110, 83, 77, 93, 144, 198,
616616
172, 116, 114, 87, 78, 93, 146, 191,
@@ -642,7 +642,7 @@ fn test_dequantize_and_idct_block_8x8_saturated() {
642642
}
643643
let mut output = [0u8; 8 * 8];
644644
dequantize_and_idct_block_8x8(&[i16::MAX; 8 * 8], &[u16::MAX; 8 * 8], 8, &mut output);
645-
#[cfg_attr(rustfmt, rustfmt_skip)]
645+
#[rustfmt::skip]
646646
let expected = [
647647
0, 0, 0, 255, 255, 0, 0, 255,
648648
0, 0, 215, 0, 0, 255, 255, 0,

src/parser.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ pub enum AppData {
9898
}
9999

100100
// http://www.sno.phy.queensu.ca/~phil/exiftool/TagNames/JPEG.html#Adobe
101+
#[allow(clippy::upper_case_acronyms)]
101102
#[derive(Clone, Copy, Debug, PartialEq)]
102103
pub enum AdobeColorTransform {
103104
// RGB or CMYK
@@ -523,6 +524,7 @@ pub fn parse_dqt<R: Read>(reader: &mut R) -> Result<[Option<[u16; 64]>; 4]> {
523524
}
524525

525526
// Section B.2.4.2
527+
#[allow(clippy::type_complexity)]
526528
pub fn parse_dht<R: Read>(reader: &mut R, is_baseline: Option<bool>) -> Result<(Vec<Option<HuffmanTable>>, Vec<Option<HuffmanTable>>)> {
527529
let mut length = read_length(reader, DHT)?;
528530
let mut dc_tables = vec![None, None, None, None];

src/upsampler.rs

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -84,29 +84,27 @@ fn choose_upsampler(sampling_factors: (u8, u8),
8484

8585
if h1 && v1 {
8686
Ok(Box::new(UpsamplerH1V1))
87-
}
88-
else if h2 && v1 {
87+
} else if h2 && v1 {
8988
Ok(Box::new(UpsamplerH2V1))
90-
}
91-
else if h1 && v2 {
89+
} else if h1 && v2 {
9290
Ok(Box::new(UpsamplerH1V2))
93-
}
94-
else if h2 && v2 {
91+
} else if h2 && v2 {
9592
Ok(Box::new(UpsamplerH2V2))
96-
}
97-
else {
98-
if max_sampling_factors.0 % sampling_factors.0 != 0 || max_sampling_factors.1 % sampling_factors.1 != 0 {
99-
Err(Error::Unsupported(UnsupportedFeature::NonIntegerSubsamplingRatio))
100-
}
101-
else {
102-
Ok(Box::new(UpsamplerGeneric {
103-
horizontal_scaling_factor: max_sampling_factors.0 / sampling_factors.0,
104-
vertical_scaling_factor: max_sampling_factors.1 / sampling_factors.1
105-
}))
106-
}
93+
} else if max_sampling_factors.0 % sampling_factors.0 != 0
94+
|| max_sampling_factors.1 % sampling_factors.1 != 0
95+
{
96+
Err(Error::Unsupported(
97+
UnsupportedFeature::NonIntegerSubsamplingRatio,
98+
))
99+
} else {
100+
Ok(Box::new(UpsamplerGeneric {
101+
horizontal_scaling_factor: max_sampling_factors.0 / sampling_factors.0,
102+
vertical_scaling_factor: max_sampling_factors.1 / sampling_factors.1,
103+
}))
107104
}
108105
}
109106

107+
#[allow(clippy::too_many_arguments)]
110108
trait Upsample {
111109
fn upsample_row(&self,
112110
input: &[u8],

src/worker/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ enum WorkerScopeInner {
5050
not(any(target_arch = "asmjs", target_arch = "wasm32")),
5151
feature = "rayon"
5252
))]
53-
Rayon(rayon::Scoped),
53+
Rayon(Box<rayon::Scoped>),
5454
#[cfg(not(any(target_arch = "asmjs", target_arch = "wasm32")))]
5555
Multithreaded(multithreaded::MpscWorker),
5656
Immediate(immediate::ImmediateWorker),
@@ -86,7 +86,7 @@ impl WorkerScope {
8686
not(any(target_arch = "asmjs", target_arch = "wasm32")),
8787
feature = "rayon"
8888
))]
89-
WorkerScopeInner::Rayon(worker) => worker,
89+
WorkerScopeInner::Rayon(worker) => worker.as_mut(),
9090
#[cfg(not(any(target_arch = "asmjs", target_arch = "wasm32")))]
9191
WorkerScopeInner::Multithreaded(worker) => worker,
9292
WorkerScopeInner::Immediate(worker) => worker,

src/worker/multithreaded.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ impl MpscWorker {
3232
) -> Result<()> {
3333
// if there is no worker thread for this component yet, start one
3434
let component = row_data.index;
35-
if let None = self.senders[component] {
35+
if self.senders[component].is_none() {
3636
let sender = spawn_worker(component)?;
3737
self.senders[component] = Some(sender);
3838
}

0 commit comments

Comments
 (0)