Skip to content

Commit a0eaac8

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 5ad7153 commit a0eaac8

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
@@ -708,7 +708,6 @@ fn UpdateNodes<AllocF: Allocator<floatX>>(
708708
let backward: usize = (posdata.distance_cache[(idx & distance_cache_len_minus_1)]
709709
+ i32::from(kDistanceCacheOffset[j])) as usize;
710710
let mut prev_ix: usize = cur_ix.wrapping_sub(backward);
711-
let len: usize;
712711
let continuation: u8 = ringbuffer[cur_ix_masked.wrapping_add(best_len)];
713712
if cur_ix_masked.wrapping_add(best_len) > ringbuffer_mask {
714713
break;
@@ -728,7 +727,7 @@ fn UpdateNodes<AllocF: Allocator<floatX>>(
728727
{
729728
continue;
730729
}
731-
len = FindMatchLengthWithLimit(
730+
let len = FindMatchLengthWithLimit(
732731
&ringbuffer[prev_ix..],
733732
&ringbuffer[cur_ix_masked..],
734733
max_len,

src/enc/brotli_bit_stream.rs

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

304304
let (prev_dist_index, dist_offset) = cmd.distance_index_and_offset(&params.dist);
305-
let final_distance: usize;
306-
if prev_dist_index == 0 {
307-
final_distance = dist_offset as usize;
305+
let final_distance = if prev_dist_index == 0 {
306+
dist_offset as usize
308307
} else {
309-
final_distance =
310-
(local_dist_cache[prev_dist_index - 1] as isize + dist_offset) as usize;
311-
}
308+
(local_dist_cache[prev_dist_index - 1] as isize + dist_offset) as usize
309+
};
312310
let copy_len = copylen_code as usize;
313311
let actual_copy_len: usize;
314312
let max_distance = min(

src/enc/encode.rs

+4-5
Original file line numberDiff line numberDiff line change
@@ -1566,15 +1566,14 @@ impl<Alloc: BrotliAlloc> BrotliEncoderStateStruct<Alloc> {
15661566
let delta: u64 = self.unprocessed_input_size();
15671567
let tail: u64 = available_in as u64;
15681568
let limit: u32 = 1u32 << 30;
1569-
let total: u32;
1570-
if delta >= u64::from(limit)
1569+
let total: u32 = if delta >= u64::from(limit)
15711570
|| tail >= u64::from(limit)
15721571
|| delta.wrapping_add(tail) >= u64::from(limit)
15731572
{
1574-
total = limit;
1573+
limit
15751574
} else {
1576-
total = delta.wrapping_add(tail) as u32;
1577-
}
1575+
delta.wrapping_add(tail) as u32
1576+
};
15781577
self.params.size_hint = total as usize;
15791578
}
15801579
}

src/enc/mod.rs

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

src/enc/reader.rs

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

0 commit comments

Comments
 (0)