Skip to content

Commit

Permalink
Merge pull request #9 from anatawa12/clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
robjtede authored Aug 13, 2023
2 parents 321f5ad + c8bd4a8 commit ba1b2ff
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 13 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
name: CI (Build)

on:
push:
branches: ["master"]
pull_request:
push:
branches: ["master"]

env:
Expand Down
6 changes: 3 additions & 3 deletions src/huffman_tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,10 +203,10 @@ impl HuffmanTree {
// For any code which has length longer than num_elements,
// build a binary tree.

let mut overflow_bits = len - Self::TABLE_BITS; // the nodes we need to respent the data.
let mut overflow_bits = len - Self::TABLE_BITS; // the nodes we need to represent the data.
let mut code_bit_mask = 1 << Self::TABLE_BITS; // mask to get current bit (the bits can't fit in the table)

// the left, right table is used to repesent the
// the left, right table is used to represent the
// the rest bits. When we got the first part (number bits.) and look at
// tbe table, we will need to follow the tree to find the real character.
// This is in place to avoid bloating the table if there are
Expand Down Expand Up @@ -257,7 +257,7 @@ impl HuffmanTree {
Ok(())
}

pub fn get_next_symbol(&self, input: &mut InputBuffer) -> Result<u16, InternalErr> {
pub fn get_next_symbol(&self, input: &mut InputBuffer<'_>) -> Result<u16, InternalErr> {
assert_ne!(self.code_lengths_length, 0, "invalid table");
// Try to load 16 bits into input buffer if possible and get the bit_buffer value.
// If there aren't 16 bits available we will return all we have in the
Expand Down
16 changes: 11 additions & 5 deletions src/inflater_managed.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::huffman_tree::HuffmanTree;
use crate::input_buffer::{BitsBuffer, InputBuffer};
use crate::output_window::OutputWindow;
use crate::*;
use crate::{array_copy, array_copy1, BlockType, InflateResult, InflaterState, InternalErr};
use std::cmp::min;

// Extra bits for length code 257 - 285.
Expand Down Expand Up @@ -73,6 +73,8 @@ pub struct InflaterManaged {

impl InflaterManaged {
/// Initializes Inflater
#[allow(clippy::new_without_default)]
#[inline]
pub fn new() -> Self {
Self::with_uncompressed_size(usize::MAX)
}
Expand Down Expand Up @@ -185,7 +187,7 @@ impl InflaterManaged {
result
}

fn decode(&mut self, input: &mut InputBuffer) -> Result<(), InternalErr> {
fn decode(&mut self, input: &mut InputBuffer<'_>) -> Result<(), InternalErr> {
let mut eob = false;
let result;

Expand Down Expand Up @@ -250,7 +252,7 @@ impl InflaterManaged {

fn decode_uncompressed_block(
&mut self,
input: &mut InputBuffer,
input: &mut InputBuffer<'_>,
end_of_block: &mut bool,
) -> Result<(), InternalErr> {
*end_of_block = false;
Expand Down Expand Up @@ -318,7 +320,7 @@ impl InflaterManaged {

fn decode_block(
&mut self,
input: &mut InputBuffer,
input: &mut InputBuffer<'_>,
end_of_block_code_seen: &mut bool,
) -> Result<(), InternalErr> {
*end_of_block_code_seen = false;
Expand All @@ -336,6 +338,7 @@ impl InflaterManaged {
// TODO: optimize this!!!
symbol = self.literal_length_tree.get_next_symbol(input)?;

#[allow(clippy::comparison_chain)]
if symbol < 256 {
// literal
self.output.write(symbol as u8);
Expand Down Expand Up @@ -447,7 +450,10 @@ impl InflaterManaged {
// The code length repeat codes can cross from HLIT + 257 to the
// HDIST + 1 code lengths. In other words, all code lengths form
// a single sequence of HLIT + HDIST + 258 values.
fn decode_dynamic_block_header(&mut self, input: &mut InputBuffer) -> Result<(), InternalErr> {
fn decode_dynamic_block_header(
&mut self,
input: &mut InputBuffer<'_>,
) -> Result<(), InternalErr> {
'switch: loop {
match self.state {
InflaterState::ReadingNumLitCodes => {
Expand Down
2 changes: 2 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
//! [dotnet]: https://github.com/dotnet/runtime/tree/e5efd8010e19593298dc2c3ee15106d5aec5a924/src/libraries/System.IO.Compression/src/System/IO/Compression/DeflateManaged

#![forbid(unsafe_code)]
#![deny(rust_2018_idioms, nonstandard_style, future_incompatible)]

mod huffman_tree;
mod inflater_managed;
Expand Down Expand Up @@ -113,6 +114,7 @@ pub struct InflateResult {

impl InflateResult {
/// Creates `InflateResult` with zero bytes consumed and written, and no error.
#[allow(clippy::new_without_default)]
pub fn new() -> Self {
Self {
bytes_consumed: 0,
Expand Down
6 changes: 3 additions & 3 deletions src/output_window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::input_buffer::InputBuffer;
use std::cmp::min;

// With Deflate64 we can have up to a 65536 length as well as up to a 65538 distance. This means we need a Window that is at
// least 131074 bytes long so we have space to retrieve up to a full 64kb in lookback and place it in our buffer without
// least 131074 bytes long so we have space to retrieve up to a full 64kb in look-back and place it in our buffer without
// overwriting existing data. OutputWindow requires that the WINDOW_SIZE be an exponent of 2, so we round up to 2^18.
const WINDOW_SIZE: usize = 262144;
const WINDOW_MASK: usize = 262143;
Expand Down Expand Up @@ -91,7 +91,7 @@ impl OutputWindow {
/// Copy up to length of bytes from input directly.
/// This is used for uncompressed block.
/// </summary>
pub fn copy_from(&mut self, input: &mut InputBuffer, mut length: usize) -> usize {
pub fn copy_from(&mut self, input: &mut InputBuffer<'_>, mut length: usize) -> usize {
length = min(
min(length, WINDOW_SIZE - self.bytes_used),
input.available_bytes(),
Expand Down Expand Up @@ -151,7 +151,7 @@ impl OutputWindow {
if output.len() > copy_end {
let tail_len = output.len() - copy_end;
// this means we need to copy two parts separately
// copy the taillen bytes from the end of the output window
// copy the tail_len bytes from the end of the output window
output[..tail_len].copy_from_slice(&self.window[WINDOW_SIZE - tail_len..][..tail_len]);
output = &mut output[tail_len..][..copy_end];
}
Expand Down

0 comments on commit ba1b2ff

Please sign in to comment.