Skip to content

Commit 113c318

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 6c4cd18 commit 113c318

File tree

5 files changed

+59
-67
lines changed

5 files changed

+59
-67
lines changed

src/enc/backward_references/hq.rs

+43-46
Original file line numberDiff line numberDiff line change
@@ -734,64 +734,61 @@ fn UpdateNodes<AllocF: Allocator<floatX>>(
734734
+ i32::from(kDistanceCacheOffset[j]))
735735
as usize;
736736
let mut prev_ix: usize = cur_ix.wrapping_sub(backward);
737-
let len: usize;
738737
let continuation: u8 = ringbuffer[cur_ix_masked.wrapping_add(best_len)];
739738
if cur_ix_masked.wrapping_add(best_len) > ringbuffer_mask {
740739
break 'break29;
741740
}
742741
if backward > max_distance.wrapping_add(gap) {
743742
break 'continue30;
744743
}
745-
if backward <= max_distance {
746-
if prev_ix >= cur_ix {
747-
break 'continue30;
748-
}
749-
prev_ix &= ringbuffer_mask;
750-
if prev_ix.wrapping_add(best_len) > ringbuffer_mask
751-
|| continuation as i32
752-
!= ringbuffer[(prev_ix.wrapping_add(best_len) as usize)]
753-
as i32
754-
{
755-
break 'continue30;
756-
}
757-
len = FindMatchLengthWithLimit(
758-
&ringbuffer[(prev_ix as usize)..],
759-
&ringbuffer[cur_ix_masked..],
760-
max_len,
761-
);
762-
} else {
744+
if backward > max_distance {
763745
break 'continue30;
764746
}
747+
748+
if prev_ix >= cur_ix {
749+
break 'continue30;
750+
}
751+
prev_ix &= ringbuffer_mask;
752+
if prev_ix.wrapping_add(best_len) > ringbuffer_mask
753+
|| continuation as i32
754+
!= ringbuffer[prev_ix.wrapping_add(best_len)] as i32
765755
{
766-
let dist_cost = base_cost + model.get_distance_cost(j);
767-
for l in best_len.wrapping_add(1)..=len {
768-
let copycode: u16 = GetCopyLengthCode(l);
769-
let cmdcode: u16 =
770-
CombineLengthCodes(inscode, copycode, (j == 0usize) as i32);
771-
let cost: floatX =
772-
(if cmdcode < 128 { base_cost } else { dist_cost })
773-
+ (GetCopyExtra(copycode) as floatX)
774-
+ model.get_command_cost(cmdcode);
775-
if cost
776-
< match (nodes[pos.wrapping_add(l)]).u {
777-
Union1::cost(cost) => cost,
778-
_ => 0.0,
779-
}
780-
{
781-
UpdateZopfliNode(
782-
nodes,
783-
pos,
784-
start,
785-
l,
786-
l,
787-
backward,
788-
j.wrapping_add(1),
789-
cost,
790-
);
791-
result = max(result, l);
756+
break 'continue30;
757+
}
758+
759+
let len = FindMatchLengthWithLimit(
760+
&ringbuffer[prev_ix..],
761+
&ringbuffer[cur_ix_masked..],
762+
max_len,
763+
);
764+
let dist_cost = base_cost + model.get_distance_cost(j);
765+
for l in best_len.wrapping_add(1)..=len {
766+
let copycode: u16 = GetCopyLengthCode(l);
767+
let cmdcode: u16 =
768+
CombineLengthCodes(inscode, copycode, (j == 0usize) as i32);
769+
let cost: floatX =
770+
(if cmdcode < 128 { base_cost } else { dist_cost })
771+
+ (GetCopyExtra(copycode) as floatX)
772+
+ model.get_command_cost(cmdcode);
773+
if cost
774+
< match (nodes[pos.wrapping_add(l)]).u {
775+
Union1::cost(cost) => cost,
776+
_ => 0.0,
792777
}
793-
best_len = l;
778+
{
779+
UpdateZopfliNode(
780+
nodes,
781+
pos,
782+
start,
783+
l,
784+
l,
785+
backward,
786+
j.wrapping_add(1),
787+
cost,
788+
);
789+
result = max(result, l);
794790
}
791+
best_len = l;
795792
}
796793
}
797794
break;

src/enc/brotli_bit_stream.rs

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

313313
let (prev_dist_index, dist_offset) = CommandDistanceIndexAndOffset(cmd, &params.dist);
314-
let final_distance: usize;
315-
if prev_dist_index == 0 {
316-
final_distance = dist_offset as usize;
314+
let final_distance = if prev_dist_index == 0 {
315+
dist_offset as usize
317316
} else {
318-
final_distance =
319-
(local_dist_cache[prev_dist_index - 1] as isize + dist_offset) as usize;
320-
}
317+
(local_dist_cache[prev_dist_index - 1] as isize + dist_offset) as usize
318+
};
321319
let copy_len = copylen_code as usize;
322320
let actual_copy_len: usize;
323321
let max_distance = min(

src/enc/encode.rs

+4-5
Original file line numberDiff line numberDiff line change
@@ -1639,15 +1639,14 @@ impl<Alloc: BrotliAlloc> BrotliEncoderStateStruct<Alloc> {
16391639
let delta: u64 = self.unprocessed_input_size();
16401640
let tail: u64 = available_in as u64;
16411641
let limit: u32 = 1u32 << 30;
1642-
let total: u32;
1643-
if delta >= u64::from(limit)
1642+
let total: u32 = if delta >= u64::from(limit)
16441643
|| tail >= u64::from(limit)
16451644
|| delta.wrapping_add(tail) >= u64::from(limit)
16461645
{
1647-
total = limit;
1646+
limit
16481647
} else {
1649-
total = delta.wrapping_add(tail) as u32;
1650-
}
1648+
delta.wrapping_add(tail) as u32
1649+
};
16511650
self.params.size_hint = total as usize;
16521651
}
16531652
}

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)