Skip to content

Commit

Permalink
Fix clippy::needless_late_init
Browse files Browse the repository at this point in the history
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
  • Loading branch information
nyurik committed Apr 8, 2024
1 parent 6c4cd18 commit 113c318
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 67 deletions.
89 changes: 43 additions & 46 deletions src/enc/backward_references/hq.rs
Original file line number Diff line number Diff line change
Expand Up @@ -734,64 +734,61 @@ fn UpdateNodes<AllocF: Allocator<floatX>>(
+ i32::from(kDistanceCacheOffset[j]))
as usize;
let mut prev_ix: usize = cur_ix.wrapping_sub(backward);
let len: usize;
let continuation: u8 = ringbuffer[cur_ix_masked.wrapping_add(best_len)];
if cur_ix_masked.wrapping_add(best_len) > ringbuffer_mask {
break 'break29;
}
if backward > max_distance.wrapping_add(gap) {
break 'continue30;
}
if backward <= max_distance {
if prev_ix >= cur_ix {
break 'continue30;
}
prev_ix &= ringbuffer_mask;
if prev_ix.wrapping_add(best_len) > ringbuffer_mask
|| continuation as i32
!= ringbuffer[(prev_ix.wrapping_add(best_len) as usize)]
as i32
{
break 'continue30;
}
len = FindMatchLengthWithLimit(
&ringbuffer[(prev_ix as usize)..],
&ringbuffer[cur_ix_masked..],
max_len,
);
} else {
if backward > max_distance {
break 'continue30;
}

if prev_ix >= cur_ix {
break 'continue30;
}
prev_ix &= ringbuffer_mask;
if prev_ix.wrapping_add(best_len) > ringbuffer_mask
|| continuation as i32
!= ringbuffer[prev_ix.wrapping_add(best_len)] as i32
{
let dist_cost = base_cost + model.get_distance_cost(j);
for l in best_len.wrapping_add(1)..=len {
let copycode: u16 = GetCopyLengthCode(l);
let cmdcode: u16 =
CombineLengthCodes(inscode, copycode, (j == 0usize) as i32);
let cost: floatX =
(if cmdcode < 128 { base_cost } else { dist_cost })
+ (GetCopyExtra(copycode) as floatX)
+ model.get_command_cost(cmdcode);
if cost
< match (nodes[pos.wrapping_add(l)]).u {
Union1::cost(cost) => cost,
_ => 0.0,
}
{
UpdateZopfliNode(
nodes,
pos,
start,
l,
l,
backward,
j.wrapping_add(1),
cost,
);
result = max(result, l);
break 'continue30;
}

let len = FindMatchLengthWithLimit(
&ringbuffer[prev_ix..],
&ringbuffer[cur_ix_masked..],
max_len,
);
let dist_cost = base_cost + model.get_distance_cost(j);
for l in best_len.wrapping_add(1)..=len {
let copycode: u16 = GetCopyLengthCode(l);
let cmdcode: u16 =
CombineLengthCodes(inscode, copycode, (j == 0usize) as i32);
let cost: floatX =
(if cmdcode < 128 { base_cost } else { dist_cost })
+ (GetCopyExtra(copycode) as floatX)
+ model.get_command_cost(cmdcode);
if cost
< match (nodes[pos.wrapping_add(l)]).u {
Union1::cost(cost) => cost,
_ => 0.0,
}
best_len = l;
{
UpdateZopfliNode(
nodes,
pos,
start,
l,
l,
backward,
j.wrapping_add(1),
cost,
);
result = max(result, l);
}
best_len = l;
}
}
break;
Expand Down
10 changes: 4 additions & 6 deletions src/enc/brotli_bit_stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -311,13 +311,11 @@ fn process_command_queue<'a, CmdProcessor: interface::CommandProcessor<'a>>(
let copylen_code = cmd.copy_len_code();

let (prev_dist_index, dist_offset) = CommandDistanceIndexAndOffset(cmd, &params.dist);
let final_distance: usize;
if prev_dist_index == 0 {
final_distance = dist_offset as usize;
let final_distance = if prev_dist_index == 0 {
dist_offset as usize
} else {
final_distance =
(local_dist_cache[prev_dist_index - 1] as isize + dist_offset) as usize;
}
(local_dist_cache[prev_dist_index - 1] as isize + dist_offset) as usize
};
let copy_len = copylen_code as usize;
let actual_copy_len: usize;
let max_distance = min(
Expand Down
9 changes: 4 additions & 5 deletions src/enc/encode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1639,15 +1639,14 @@ impl<Alloc: BrotliAlloc> BrotliEncoderStateStruct<Alloc> {
let delta: u64 = self.unprocessed_input_size();
let tail: u64 = available_in as u64;
let limit: u32 = 1u32 << 30;
let total: u32;
if delta >= u64::from(limit)
let total: u32 = if delta >= u64::from(limit)
|| tail >= u64::from(limit)
|| delta.wrapping_add(tail) >= u64::from(limit)
{
total = limit;
limit
} else {
total = delta.wrapping_add(tail) as u32;
}
delta.wrapping_add(tail) as u32
};
self.params.size_hint = total as usize;
}
}
Expand Down
9 changes: 4 additions & 5 deletions src/enc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -291,12 +291,11 @@ where
}
}
}
let op: BrotliEncoderOperation;
if available_in == 0 {
op = BrotliEncoderOperation::BROTLI_OPERATION_FINISH;
let op = if available_in == 0 {
BrotliEncoderOperation::BROTLI_OPERATION_FINISH
} else {
op = BrotliEncoderOperation::BROTLI_OPERATION_PROCESS;
}
BrotliEncoderOperation::BROTLI_OPERATION_PROCESS
};
let result = s.compress_stream(
op,
&mut available_in,
Expand Down
9 changes: 4 additions & 5 deletions src/enc/reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -221,12 +221,11 @@ impl<ErrType, R: CustomRead<ErrType>, BufferType: SliceWrapperMut<u8>, Alloc: Br
}
}
}
let op: BrotliEncoderOperation;
if avail_in == 0 {
op = BrotliEncoderOperation::BROTLI_OPERATION_FINISH;
let op = if avail_in == 0 {
BrotliEncoderOperation::BROTLI_OPERATION_FINISH
} else {
op = BrotliEncoderOperation::BROTLI_OPERATION_PROCESS;
}
BrotliEncoderOperation::BROTLI_OPERATION_PROCESS
};
let ret = self.state.0.compress_stream(
op,
&mut avail_in,
Expand Down

0 comments on commit 113c318

Please sign in to comment.