Skip to content

Commit 0465516

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 c35494b commit 0465516

File tree

5 files changed

+17
-23
lines changed

5 files changed

+17
-23
lines changed

src/enc/backward_references/hq.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -707,7 +707,6 @@ fn UpdateNodes<AllocF: Allocator<floatX>>(
707707
let backward: usize = (posdata.distance_cache[(idx & distance_cache_len_minus_1)]
708708
+ i32::from(kDistanceCacheOffset[j])) as usize;
709709
let mut prev_ix: usize = cur_ix.wrapping_sub(backward);
710-
let len: usize;
711710
let continuation: u8 = ringbuffer[cur_ix_masked.wrapping_add(best_len)];
712711
if cur_ix_masked.wrapping_add(best_len) > ringbuffer_mask {
713712
break;
@@ -727,7 +726,7 @@ fn UpdateNodes<AllocF: Allocator<floatX>>(
727726
{
728727
continue;
729728
}
730-
len = FindMatchLengthWithLimit(
729+
let len = FindMatchLengthWithLimit(
731730
&ringbuffer[prev_ix..],
732731
&ringbuffer[cur_ix_masked..],
733732
max_len,

src/enc/brotli_bit_stream.rs

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

301301
let (prev_dist_index, dist_offset) = cmd.distance_index_and_offset(&params.dist);
302-
let final_distance: usize;
303-
if prev_dist_index == 0 {
304-
final_distance = dist_offset as usize;
302+
let final_distance = if prev_dist_index == 0 {
303+
dist_offset as usize
305304
} else {
306-
final_distance =
307-
(local_dist_cache[prev_dist_index - 1] as isize + dist_offset) as usize;
308-
}
305+
(local_dist_cache[prev_dist_index - 1] as isize + dist_offset) as usize
306+
};
309307
let copy_len = copylen_code as usize;
310308
let actual_copy_len: usize;
311309
let max_distance = min(

src/enc/encode.rs

+4-5
Original file line numberDiff line numberDiff line change
@@ -1604,15 +1604,14 @@ impl<Alloc: BrotliAlloc> BrotliEncoderStateStruct<Alloc> {
16041604
let delta: u64 = self.unprocessed_input_size();
16051605
let tail: u64 = available_in as u64;
16061606
let limit: u32 = 1u32 << 30;
1607-
let total: u32;
1608-
if delta >= u64::from(limit)
1607+
let total: u32 = if delta >= u64::from(limit)
16091608
|| tail >= u64::from(limit)
16101609
|| delta.wrapping_add(tail) >= u64::from(limit)
16111610
{
1612-
total = limit;
1611+
limit
16131612
} else {
1614-
total = delta.wrapping_add(tail) as u32;
1615-
}
1613+
delta.wrapping_add(tail) as u32
1614+
};
16161615
self.params.size_hint = total as usize;
16171616
}
16181617
}

src/enc/mod.rs

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

src/enc/reader.rs

+4-5
Original file line numberDiff line numberDiff line change
@@ -219,12 +219,11 @@ impl<ErrType, R: CustomRead<ErrType>, BufferType: SliceWrapperMut<u8>, Alloc: Br
219219
}
220220
}
221221
}
222-
let op: BrotliEncoderOperation;
223-
if avail_in == 0 {
224-
op = BrotliEncoderOperation::BROTLI_OPERATION_FINISH;
222+
let op = if avail_in == 0 {
223+
BrotliEncoderOperation::BROTLI_OPERATION_FINISH
225224
} else {
226-
op = BrotliEncoderOperation::BROTLI_OPERATION_PROCESS;
227-
}
225+
BrotliEncoderOperation::BROTLI_OPERATION_PROCESS
226+
};
228227
let ret = self.state.0.compress_stream(
229228
op,
230229
&mut avail_in,

0 commit comments

Comments
 (0)