Skip to content

Commit 972726e

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 f8f5840 commit 972726e

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
@@ -733,64 +733,61 @@ fn UpdateNodes<AllocF: Allocator<floatX>>(
733733
+ i32::from(kDistanceCacheOffset[j]))
734734
as usize;
735735
let mut prev_ix: usize = cur_ix.wrapping_sub(backward);
736-
let len: usize;
737736
let continuation: u8 = ringbuffer[cur_ix_masked.wrapping_add(best_len)];
738737
if cur_ix_masked.wrapping_add(best_len) > ringbuffer_mask {
739738
break 'break29;
740739
}
741740
if backward > max_distance.wrapping_add(gap) {
742741
break 'continue30;
743742
}
744-
if backward <= max_distance {
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 usize)]
752-
as i32
753-
{
754-
break 'continue30;
755-
}
756-
len = FindMatchLengthWithLimit(
757-
&ringbuffer[(prev_ix as usize)..],
758-
&ringbuffer[cur_ix_masked..],
759-
max_len,
760-
);
761-
} else {
743+
if backward > max_distance {
762744
break 'continue30;
763745
}
746+
747+
if prev_ix >= cur_ix {
748+
break 'continue30;
749+
}
750+
prev_ix &= ringbuffer_mask;
751+
if prev_ix.wrapping_add(best_len) > ringbuffer_mask
752+
|| continuation as i32
753+
!= ringbuffer[prev_ix.wrapping_add(best_len)] as i32
764754
{
765-
let dist_cost = base_cost + model.get_distance_cost(j);
766-
for l in best_len.wrapping_add(1)..=len {
767-
let copycode: u16 = GetCopyLengthCode(l);
768-
let cmdcode: u16 =
769-
CombineLengthCodes(inscode, copycode, (j == 0usize) as i32);
770-
let cost: floatX =
771-
(if cmdcode < 128 { base_cost } else { dist_cost })
772-
+ (GetCopyExtra(copycode) as floatX)
773-
+ model.get_command_cost(cmdcode);
774-
if cost
775-
< match (nodes[pos.wrapping_add(l)]).u {
776-
Union1::cost(cost) => cost,
777-
_ => 0.0,
778-
}
779-
{
780-
UpdateZopfliNode(
781-
nodes,
782-
pos,
783-
start,
784-
l,
785-
l,
786-
backward,
787-
j.wrapping_add(1),
788-
cost,
789-
);
790-
result = max(result, l);
755+
break 'continue30;
756+
}
757+
758+
let len = FindMatchLengthWithLimit(
759+
&ringbuffer[prev_ix..],
760+
&ringbuffer[cur_ix_masked..],
761+
max_len,
762+
);
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,
791776
}
792-
best_len = l;
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);
793789
}
790+
best_len = l;
794791
}
795792
}
796793
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)