Skip to content

Commit 0c04667

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 d7d8b2d commit 0c04667

File tree

5 files changed

+65
-81
lines changed

5 files changed

+65
-81
lines changed

src/enc/backward_references/hq.rs

+45-55
Original file line numberDiff line numberDiff line change
@@ -793,74 +793,64 @@ fn UpdateNodes<AllocF: Allocator<floatX>>(
793793
+ i32::from(kDistanceCacheOffset[j]))
794794
as usize;
795795
let mut prev_ix: usize = cur_ix.wrapping_sub(backward);
796-
let len: usize;
797796
let continuation: u8 = ringbuffer[cur_ix_masked.wrapping_add(best_len)];
798797
if cur_ix_masked.wrapping_add(best_len) > ringbuffer_mask {
799798
break 'break29;
800799
}
801800
if backward > max_distance.wrapping_add(gap) {
802801
break 'continue30;
803802
}
804-
if backward <= max_distance {
805-
if prev_ix >= cur_ix {
806-
break 'continue30;
807-
}
808-
prev_ix &= ringbuffer_mask;
809-
if prev_ix.wrapping_add(best_len) > ringbuffer_mask
810-
|| continuation as i32
811-
!= ringbuffer[(prev_ix.wrapping_add(best_len) as usize)]
812-
as i32
813-
{
814-
break 'continue30;
815-
}
816-
len = FindMatchLengthWithLimit(
817-
&ringbuffer[(prev_ix as usize)..],
818-
&ringbuffer[cur_ix_masked..],
819-
max_len,
820-
);
821-
} else {
803+
if backward > max_distance {
804+
break 'continue30;
805+
}
806+
807+
if prev_ix >= cur_ix {
822808
break 'continue30;
823809
}
810+
prev_ix &= ringbuffer_mask;
811+
if prev_ix.wrapping_add(best_len) > ringbuffer_mask
812+
|| continuation as i32
813+
!= ringbuffer[prev_ix.wrapping_add(best_len)] as i32
824814
{
825-
let dist_cost: floatX =
826-
base_cost + ZopfliCostModelGetDistanceCost(model, j);
827-
let mut l: usize;
828-
l = best_len.wrapping_add(1);
829-
while l <= len {
815+
break 'continue30;
816+
}
817+
818+
let dist_cost = base_cost + ZopfliCostModelGetDistanceCost(model, j);
819+
let len = FindMatchLengthWithLimit(
820+
&ringbuffer[prev_ix..],
821+
&ringbuffer[cur_ix_masked..],
822+
max_len,
823+
);
824+
for l in best_len.wrapping_add(1)..=len {
825+
{
826+
let copycode: u16 = GetCopyLengthCode(l);
827+
let cmdcode: u16 =
828+
CombineLengthCodes(inscode, copycode, (j == 0usize) as i32);
829+
let cost: floatX = (if (cmdcode as i32) < 128i32 {
830+
base_cost
831+
} else {
832+
dist_cost
833+
}) + GetCopyExtra(copycode) as (floatX)
834+
+ ZopfliCostModelGetCommandCost(model, cmdcode);
835+
if cost
836+
< match (nodes[pos.wrapping_add(l)]).u {
837+
Union1::cost(cost) => cost,
838+
_ => 0.0,
839+
}
830840
{
831-
let copycode: u16 = GetCopyLengthCode(l);
832-
let cmdcode: u16 = CombineLengthCodes(
833-
inscode,
834-
copycode,
835-
(j == 0usize) as i32,
841+
UpdateZopfliNode(
842+
nodes,
843+
pos,
844+
start,
845+
l,
846+
l,
847+
backward,
848+
j.wrapping_add(1),
849+
cost,
836850
);
837-
let cost: floatX = (if (cmdcode as i32) < 128i32 {
838-
base_cost
839-
} else {
840-
dist_cost
841-
}) + GetCopyExtra(copycode) as (floatX)
842-
+ ZopfliCostModelGetCommandCost(model, cmdcode);
843-
if cost
844-
< match (nodes[pos.wrapping_add(l)]).u {
845-
Union1::cost(cost) => cost,
846-
_ => 0.0,
847-
}
848-
{
849-
UpdateZopfliNode(
850-
nodes,
851-
pos,
852-
start,
853-
l,
854-
l,
855-
backward,
856-
j.wrapping_add(1),
857-
cost,
858-
);
859-
result = brotli_max_size_t(result, l);
860-
}
861-
best_len = l;
851+
result = brotli_max_size_t(result, l);
862852
}
863-
l = l.wrapping_add(1);
853+
best_len = l;
864854
}
865855
}
866856
}

src/enc/brotli_bit_stream.rs

+8-11
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(
@@ -1428,12 +1426,11 @@ fn NewBlockEncoder<'a, Alloc: alloc::Allocator<u8> + alloc::Allocator<u16>>(
14281426
block_lengths: &'a [u32],
14291427
num_blocks: usize,
14301428
) -> BlockEncoder<'a, Alloc> {
1431-
let block_len: usize;
1432-
if num_blocks != 0 && !block_lengths.is_empty() {
1433-
block_len = block_lengths[0] as usize;
1429+
let block_len = if num_blocks != 0 && !block_lengths.is_empty() {
1430+
block_lengths[0] as usize
14341431
} else {
1435-
block_len = 0;
1436-
}
1432+
0
1433+
};
14371434
BlockEncoder::<Alloc> {
14381435
histogram_length_: histogram_length,
14391436
num_block_types_: num_block_types,

src/enc/encode.rs

+4-5
Original file line numberDiff line numberDiff line change
@@ -1686,15 +1686,14 @@ fn UpdateSizeHint<Alloc: BrotliAlloc>(
16861686
let delta: u64 = UnprocessedInputSize(s);
16871687
let tail: u64 = available_in as u64;
16881688
let limit: u32 = 1u32 << 30;
1689-
let total: u32;
1690-
if delta >= u64::from(limit)
1689+
let total: u32 = if delta >= u64::from(limit)
16911690
|| tail >= u64::from(limit)
16921691
|| delta.wrapping_add(tail) >= u64::from(limit)
16931692
{
1694-
total = limit;
1693+
limit
16951694
} else {
1696-
total = delta.wrapping_add(tail) as u32;
1697-
}
1695+
delta.wrapping_add(tail) as u32
1696+
};
16981697
s.params.size_hint = total as usize;
16991698
}
17001699
}

src/enc/mod.rs

+4-5
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

+4-5
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)