Skip to content

Commit 68e105a

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 68e105a

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
@@ -731,64 +731,61 @@ 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 {
760742
break 'continue30;
761743
}
744+
745+
if prev_ix >= cur_ix {
746+
break 'continue30;
747+
}
748+
prev_ix &= ringbuffer_mask;
749+
if prev_ix.wrapping_add(best_len) > ringbuffer_mask
750+
|| continuation as i32
751+
!= ringbuffer[prev_ix.wrapping_add(best_len)] as i32
762752
{
763-
let dist_cost = base_cost + model.get_distance_cost(j);
764-
for l in best_len.wrapping_add(1)..=len {
765-
let copycode: u16 = GetCopyLengthCode(l);
766-
let cmdcode: u16 =
767-
CombineLengthCodes(inscode, copycode, (j == 0usize) as i32);
768-
let cost: floatX =
769-
(if cmdcode < 128 { base_cost } else { dist_cost })
770-
+ (GetCopyExtra(copycode) as floatX)
771-
+ model.get_command_cost(cmdcode);
772-
if cost
773-
< match (nodes[pos.wrapping_add(l)]).u {
774-
Union1::cost(cost) => cost,
775-
_ => 0.0,
776-
}
777-
{
778-
UpdateZopfliNode(
779-
nodes,
780-
pos,
781-
start,
782-
l,
783-
l,
784-
backward,
785-
j.wrapping_add(1),
786-
cost,
787-
);
788-
result = max(result, l);
753+
break 'continue30;
754+
}
755+
756+
let len = FindMatchLengthWithLimit(
757+
&ringbuffer[prev_ix..],
758+
&ringbuffer[cur_ix_masked..],
759+
max_len,
760+
);
761+
let dist_cost = base_cost + model.get_distance_cost(j);
762+
for l in best_len.wrapping_add(1)..=len {
763+
let copycode: u16 = GetCopyLengthCode(l);
764+
let cmdcode: u16 =
765+
CombineLengthCodes(inscode, copycode, (j == 0usize) as i32);
766+
let cost: floatX =
767+
(if cmdcode < 128 { base_cost } else { dist_cost })
768+
+ (GetCopyExtra(copycode) as floatX)
769+
+ model.get_command_cost(cmdcode);
770+
if cost
771+
< match (nodes[pos.wrapping_add(l)]).u {
772+
Union1::cost(cost) => cost,
773+
_ => 0.0,
789774
}
790-
best_len = l;
775+
{
776+
UpdateZopfliNode(
777+
nodes,
778+
pos,
779+
start,
780+
l,
781+
l,
782+
backward,
783+
j.wrapping_add(1),
784+
cost,
785+
);
786+
result = max(result, l);
791787
}
788+
best_len = l;
792789
}
793790
}
794791
break;

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)