Skip to content

Commit 372b92d

Browse files
committed
Fix clippy::needless_late_init
Used `cargo clippy -- -A clippy::all -W clippy::needless_late_init` to find all such cases, and manually fix them Additionally simplified logic in backward_references/hq.rs, and converted while into for loop there
1 parent bf3db20 commit 372b92d

File tree

5 files changed

+32
-40
lines changed

5 files changed

+32
-40
lines changed

src/enc/backward_references/hq.rs

+16-19
Original file line numberDiff line numberDiff line change
@@ -731,34 +731,31 @@ fn UpdateNodes<AllocF: Allocator<floatX>>(
731731
+ i32::from(kDistanceCacheOffset[j]))
732732
as usize;
733733
let mut prev_ix: usize = cur_ix.wrapping_sub(backward);
734-
let len: usize;
735734
let continuation: u8 = ringbuffer[cur_ix_masked.wrapping_add(best_len)];
736735
if cur_ix_masked.wrapping_add(best_len) > ringbuffer_mask {
737736
break 'break29;
738737
}
739738
if backward > max_distance.wrapping_add(gap) {
740739
break 'continue30;
741740
}
742-
if backward <= max_distance {
743-
if prev_ix >= cur_ix {
744-
break 'continue30;
745-
}
746-
prev_ix &= ringbuffer_mask;
747-
if prev_ix.wrapping_add(best_len) > ringbuffer_mask
748-
|| continuation as i32
749-
!= ringbuffer[(prev_ix.wrapping_add(best_len) as usize)]
750-
as i32
751-
{
752-
break 'continue30;
753-
}
754-
len = FindMatchLengthWithLimit(
755-
&ringbuffer[(prev_ix as usize)..],
756-
&ringbuffer[cur_ix_masked..],
757-
max_len,
758-
);
759-
} else {
741+
if backward > max_distance {
742+
break 'continue30;
743+
}
744+
if prev_ix >= cur_ix {
760745
break 'continue30;
761746
}
747+
prev_ix &= ringbuffer_mask;
748+
if prev_ix.wrapping_add(best_len) > ringbuffer_mask
749+
|| continuation as i32
750+
!= ringbuffer[(prev_ix.wrapping_add(best_len) as usize)] as i32
751+
{
752+
break 'continue30;
753+
}
754+
let len = FindMatchLengthWithLimit(
755+
&ringbuffer[(prev_ix as usize)..],
756+
&ringbuffer[cur_ix_masked..],
757+
max_len,
758+
);
762759
{
763760
let dist_cost = base_cost + model.get_distance_cost(j);
764761
for l in best_len.wrapping_add(1)..=len {

src/enc/brotli_bit_stream.rs

+4-6
Original file line numberDiff line numberDiff line change
@@ -309,13 +309,11 @@ fn process_command_queue<'a, CmdProcessor: interface::CommandProcessor<'a>>(
309309
let copylen_code = cmd.copy_len_code();
310310

311311
let (prev_dist_index, dist_offset) = cmd.distance_index_and_offset(&params.dist);
312-
let final_distance: usize;
313-
if prev_dist_index == 0 {
314-
final_distance = dist_offset as usize;
312+
let final_distance = if prev_dist_index == 0 {
313+
dist_offset as usize
315314
} else {
316-
final_distance =
317-
(local_dist_cache[prev_dist_index - 1] as isize + dist_offset) as usize;
318-
}
315+
(local_dist_cache[prev_dist_index - 1] as isize + dist_offset) as usize
316+
};
319317
let copy_len = copylen_code as usize;
320318
let actual_copy_len: usize;
321319
let max_distance = min(

src/enc/encode.rs

+4-5
Original file line numberDiff line numberDiff line change
@@ -1572,15 +1572,14 @@ impl<Alloc: BrotliAlloc> BrotliEncoderStateStruct<Alloc> {
15721572
let delta: u64 = self.unprocessed_input_size();
15731573
let tail: u64 = available_in as u64;
15741574
let limit: u32 = 1u32 << 30;
1575-
let total: u32;
1576-
if delta >= u64::from(limit)
1575+
let total: u32 = if delta >= u64::from(limit)
15771576
|| tail >= u64::from(limit)
15781577
|| delta.wrapping_add(tail) >= u64::from(limit)
15791578
{
1580-
total = limit;
1579+
limit
15811580
} else {
1582-
total = delta.wrapping_add(tail) as u32;
1583-
}
1581+
delta.wrapping_add(tail) as u32
1582+
};
15841583
self.params.size_hint = total as usize;
15851584
}
15861585
}

src/enc/mod.rs

+4-5
Original file line numberDiff line numberDiff line change
@@ -291,12 +291,11 @@ where
291291
}
292292
}
293293
}
294-
let op: BrotliEncoderOperation;
295-
if available_in == 0 {
296-
op = BrotliEncoderOperation::BROTLI_OPERATION_FINISH;
294+
let op = if available_in == 0 {
295+
BrotliEncoderOperation::BROTLI_OPERATION_FINISH
297296
} else {
298-
op = BrotliEncoderOperation::BROTLI_OPERATION_PROCESS;
299-
}
297+
BrotliEncoderOperation::BROTLI_OPERATION_PROCESS
298+
};
300299
let result = s.compress_stream(
301300
op,
302301
&mut available_in,

src/enc/reader.rs

+4-5
Original file line numberDiff line numberDiff line change
@@ -221,12 +221,11 @@ impl<ErrType, R: CustomRead<ErrType>, BufferType: SliceWrapperMut<u8>, Alloc: Br
221221
}
222222
}
223223
}
224-
let op: BrotliEncoderOperation;
225-
if avail_in == 0 {
226-
op = BrotliEncoderOperation::BROTLI_OPERATION_FINISH;
224+
let op = if avail_in == 0 {
225+
BrotliEncoderOperation::BROTLI_OPERATION_FINISH
227226
} else {
228-
op = BrotliEncoderOperation::BROTLI_OPERATION_PROCESS;
229-
}
227+
BrotliEncoderOperation::BROTLI_OPERATION_PROCESS
228+
};
230229
let ret = self.state.0.compress_stream(
231230
op,
232231
&mut avail_in,

0 commit comments

Comments
 (0)