Skip to content

Commit 17b19f1

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 37d403b commit 17b19f1

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
@@ -695,7 +695,6 @@ fn UpdateNodes<AllocF: Allocator<floatX>>(
695695
let backward: usize = (posdata.distance_cache[(idx & distance_cache_len_minus_1)]
696696
+ i32::from(kDistanceCacheOffset[j])) as usize;
697697
let mut prev_ix: usize = cur_ix.wrapping_sub(backward);
698-
let len: usize;
699698
let continuation: u8 = ringbuffer[cur_ix_masked.wrapping_add(best_len)];
700699
if cur_ix_masked.wrapping_add(best_len) > ringbuffer_mask {
701700
break;
@@ -715,7 +714,7 @@ fn UpdateNodes<AllocF: Allocator<floatX>>(
715714
{
716715
continue;
717716
}
718-
len = FindMatchLengthWithLimit(
717+
let len = FindMatchLengthWithLimit(
719718
&ringbuffer[prev_ix..],
720719
&ringbuffer[cur_ix_masked..],
721720
max_len,

src/enc/brotli_bit_stream.rs

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

262262
let (prev_dist_index, dist_offset) = cmd.distance_index_and_offset(&params.dist);
263-
let final_distance: usize;
264-
if prev_dist_index == 0 {
265-
final_distance = dist_offset as usize;
263+
let final_distance = if prev_dist_index == 0 {
264+
dist_offset as usize
266265
} else {
267-
final_distance =
268-
(local_dist_cache[prev_dist_index - 1] as isize + dist_offset) as usize;
269-
}
266+
(local_dist_cache[prev_dist_index - 1] as isize + dist_offset) as usize
267+
};
270268
let copy_len = copylen_code as usize;
271269
let actual_copy_len: usize;
272270
let max_distance = min(

src/enc/encode.rs

+4-5
Original file line numberDiff line numberDiff line change
@@ -1596,15 +1596,14 @@ impl<Alloc: BrotliAlloc> BrotliEncoderStateStruct<Alloc> {
15961596
let delta: u64 = self.unprocessed_input_size();
15971597
let tail: u64 = available_in as u64;
15981598
let limit: u32 = 1u32 << 30;
1599-
let total: u32;
1600-
if delta >= u64::from(limit)
1599+
let total: u32 = if delta >= u64::from(limit)
16011600
|| tail >= u64::from(limit)
16021601
|| delta.wrapping_add(tail) >= u64::from(limit)
16031602
{
1604-
total = limit;
1603+
limit
16051604
} else {
1606-
total = delta.wrapping_add(tail) as u32;
1607-
}
1605+
delta.wrapping_add(tail) as u32
1606+
};
16081607
self.params.size_hint = total as usize;
16091608
}
16101609
}

src/enc/mod.rs

+4-5
Original file line numberDiff line numberDiff line change
@@ -294,12 +294,11 @@ where
294294
}
295295
}
296296
}
297-
let op: BrotliEncoderOperation;
298-
if available_in == 0 {
299-
op = BrotliEncoderOperation::BROTLI_OPERATION_FINISH;
297+
let op = if available_in == 0 {
298+
BrotliEncoderOperation::BROTLI_OPERATION_FINISH
300299
} else {
301-
op = BrotliEncoderOperation::BROTLI_OPERATION_PROCESS;
302-
}
300+
BrotliEncoderOperation::BROTLI_OPERATION_PROCESS
301+
};
303302
let result = s.compress_stream(
304303
op,
305304
&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)