Skip to content

Commit 8bebfce

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 6fae4d3 commit 8bebfce

File tree

5 files changed

+65
-81
lines changed

5 files changed

+65
-81
lines changed

src/enc/backward_references/hq.rs

Lines changed: 45 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -775,74 +775,64 @@ fn UpdateNodes<AllocF: Allocator<floatX>>(
775775
+ i32::from(kDistanceCacheOffset[j]))
776776
as usize;
777777
let mut prev_ix: usize = cur_ix.wrapping_sub(backward);
778-
let len: usize;
779778
let continuation: u8 = ringbuffer[cur_ix_masked.wrapping_add(best_len)];
780779
if cur_ix_masked.wrapping_add(best_len) > ringbuffer_mask {
781780
break 'break29;
782781
}
783782
if backward > max_distance.wrapping_add(gap) {
784783
break 'continue30;
785784
}
786-
if backward <= max_distance {
787-
if prev_ix >= cur_ix {
788-
break 'continue30;
789-
}
790-
prev_ix &= ringbuffer_mask;
791-
if prev_ix.wrapping_add(best_len) > ringbuffer_mask
792-
|| continuation as i32
793-
!= ringbuffer[(prev_ix.wrapping_add(best_len) as usize)]
794-
as i32
795-
{
796-
break 'continue30;
797-
}
798-
len = FindMatchLengthWithLimit(
799-
&ringbuffer[(prev_ix as usize)..],
800-
&ringbuffer[cur_ix_masked..],
801-
max_len,
802-
);
803-
} else {
785+
if backward > max_distance {
804786
break 'continue30;
805787
}
788+
789+
if prev_ix >= cur_ix {
790+
break 'continue30;
791+
}
792+
prev_ix &= ringbuffer_mask;
793+
if prev_ix.wrapping_add(best_len) > ringbuffer_mask
794+
|| continuation as i32
795+
!= ringbuffer[prev_ix.wrapping_add(best_len)] as i32
806796
{
807-
let dist_cost: floatX =
808-
base_cost + ZopfliCostModelGetDistanceCost(model, j);
809-
let mut l: usize;
810-
l = best_len.wrapping_add(1);
811-
while l <= len {
797+
break 'continue30;
798+
}
799+
800+
let dist_cost = base_cost + ZopfliCostModelGetDistanceCost(model, j);
801+
let len = FindMatchLengthWithLimit(
802+
&ringbuffer[prev_ix..],
803+
&ringbuffer[cur_ix_masked..],
804+
max_len,
805+
);
806+
for l in best_len.wrapping_add(1)..=len {
807+
{
808+
let copycode: u16 = GetCopyLengthCode(l);
809+
let cmdcode: u16 =
810+
CombineLengthCodes(inscode, copycode, (j == 0usize) as i32);
811+
let cost: floatX = (if (cmdcode as i32) < 128i32 {
812+
base_cost
813+
} else {
814+
dist_cost
815+
}) + GetCopyExtra(copycode) as (floatX)
816+
+ ZopfliCostModelGetCommandCost(model, cmdcode);
817+
if cost
818+
< match (nodes[pos.wrapping_add(l)]).u {
819+
Union1::cost(cost) => cost,
820+
_ => 0.0,
821+
}
812822
{
813-
let copycode: u16 = GetCopyLengthCode(l);
814-
let cmdcode: u16 = CombineLengthCodes(
815-
inscode,
816-
copycode,
817-
(j == 0usize) as i32,
823+
UpdateZopfliNode(
824+
nodes,
825+
pos,
826+
start,
827+
l,
828+
l,
829+
backward,
830+
j.wrapping_add(1),
831+
cost,
818832
);
819-
let cost: floatX = (if (cmdcode as i32) < 128i32 {
820-
base_cost
821-
} else {
822-
dist_cost
823-
}) + GetCopyExtra(copycode) as (floatX)
824-
+ ZopfliCostModelGetCommandCost(model, cmdcode);
825-
if cost
826-
< match (nodes[pos.wrapping_add(l)]).u {
827-
Union1::cost(cost) => cost,
828-
_ => 0.0,
829-
}
830-
{
831-
UpdateZopfliNode(
832-
nodes,
833-
pos,
834-
start,
835-
l,
836-
l,
837-
backward,
838-
j.wrapping_add(1),
839-
cost,
840-
);
841-
result = brotli_max_size_t(result, l);
842-
}
843-
best_len = l;
833+
result = brotli_max_size_t(result, l);
844834
}
845-
l = l.wrapping_add(1);
835+
best_len = l;
846836
}
847837
}
848838
}

src/enc/brotli_bit_stream.rs

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -312,13 +312,11 @@ fn process_command_queue<'a, CmdProcessor: interface::CommandProcessor<'a>>(
312312
let copylen_code: u32 = CommandCopyLenCode(cmd);
313313

314314
let (prev_dist_index, dist_offset) = CommandDistanceIndexAndOffset(cmd, &params.dist);
315-
let final_distance: usize;
316-
if prev_dist_index == 0 {
317-
final_distance = dist_offset as usize;
315+
let final_distance = if prev_dist_index == 0 {
316+
dist_offset as usize
318317
} else {
319-
final_distance =
320-
(local_dist_cache[prev_dist_index - 1] as isize + dist_offset) as usize;
321-
}
318+
(local_dist_cache[prev_dist_index - 1] as isize + dist_offset) as usize
319+
};
322320
let copy_len = copylen_code as usize;
323321
let actual_copy_len: usize;
324322
let max_distance = core::cmp::min(
@@ -1413,12 +1411,11 @@ fn NewBlockEncoder<'a, Alloc: alloc::Allocator<u8> + alloc::Allocator<u16>>(
14131411
block_lengths: &'a [u32],
14141412
num_blocks: usize,
14151413
) -> BlockEncoder<'a, Alloc> {
1416-
let block_len: usize;
1417-
if num_blocks != 0 && !block_lengths.is_empty() {
1418-
block_len = block_lengths[0] as usize;
1414+
let block_len = if num_blocks != 0 && !block_lengths.is_empty() {
1415+
block_lengths[0] as usize
14191416
} else {
1420-
block_len = 0;
1421-
}
1417+
0
1418+
};
14221419
BlockEncoder::<Alloc> {
14231420
histogram_length_: histogram_length,
14241421
num_block_types_: num_block_types,

src/enc/encode.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1660,15 +1660,14 @@ fn UpdateSizeHint<Alloc: BrotliAlloc>(
16601660
let delta: u64 = UnprocessedInputSize(s);
16611661
let tail: u64 = available_in as u64;
16621662
let limit: u32 = 1u32 << 30;
1663-
let total: u32;
1664-
if delta >= u64::from(limit)
1663+
let total: u32 = if delta >= u64::from(limit)
16651664
|| tail >= u64::from(limit)
16661665
|| delta.wrapping_add(tail) >= u64::from(limit)
16671666
{
1668-
total = limit;
1667+
limit
16691668
} else {
1670-
total = delta.wrapping_add(tail) as u32;
1671-
}
1669+
delta.wrapping_add(tail) as u32
1670+
};
16721671
s.params.size_hint = total as usize;
16731672
}
16741673
}

src/enc/mod.rs

Lines changed: 4 additions & 5 deletions
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 = BrotliEncoderCompressStream(
304303
s,
305304
op,

src/enc/reader.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -226,12 +226,11 @@ impl<ErrType, R: CustomRead<ErrType>, BufferType: SliceWrapperMut<u8>, Alloc: Br
226226
}
227227
}
228228
}
229-
let op: BrotliEncoderOperation;
230-
if avail_in == 0 {
231-
op = BrotliEncoderOperation::BROTLI_OPERATION_FINISH;
229+
let op = if avail_in == 0 {
230+
BrotliEncoderOperation::BROTLI_OPERATION_FINISH
232231
} else {
233-
op = BrotliEncoderOperation::BROTLI_OPERATION_PROCESS;
234-
}
232+
BrotliEncoderOperation::BROTLI_OPERATION_PROCESS
233+
};
235234
let ret = BrotliEncoderCompressStream(
236235
&mut self.state.0,
237236
op,

0 commit comments

Comments
 (0)