Skip to content

Commit

Permalink
Replace HashBuffers arrays with Vec
Browse files Browse the repository at this point in the history
  • Loading branch information
Lonami committed Mar 2, 2024
1 parent 79307d7 commit 60ed8cb
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 16 deletions.
23 changes: 9 additions & 14 deletions miniz_oxide/src/deflate/buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
//! to avoid stack copies. Box::new() doesn't at the moment, and using a vec means we would lose
//! static length info.
use alloc::vec::Vec;

use crate::deflate::core::{LZ_DICT_SIZE, MAX_MATCH_LEN};

/// Size of the buffer of lz77 encoded data.
Expand All @@ -22,26 +24,19 @@ pub fn update_hash(current_hash: u16, byte: u8) -> u16 {
((current_hash << LZ_HASH_SHIFT) ^ u16::from(byte)) & (LZ_HASH_SIZE as u16 - 1)
}

#[derive(Default)]
pub struct HashBuffers {
pub dict: [u8; LZ_DICT_FULL_SIZE],
pub next: [u16; LZ_DICT_SIZE],
pub hash: [u16; LZ_DICT_SIZE],
pub dict: Vec<u8>,
pub next: Vec<u16>,
pub hash: Vec<u16>,
}

impl HashBuffers {
#[inline]
pub fn reset(&mut self) {
*self = HashBuffers::default();
}
}

impl Default for HashBuffers {
fn default() -> HashBuffers {
HashBuffers {
dict: [0; LZ_DICT_FULL_SIZE],
next: [0; LZ_DICT_SIZE],
hash: [0; LZ_DICT_SIZE],
}
self.dict.fill(0);
self.next.fill(0);
self.hash.fill(0);
}
}

Expand Down
4 changes: 2 additions & 2 deletions miniz_oxide/src/deflate/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1195,7 +1195,7 @@ struct DictOxide {
pub max_probes: [u32; 2],
/// Buffer of input data.
/// Padded with 1 byte to simplify matching code in `compress_fast`.
pub b: Box<HashBuffers>,
pub b: HashBuffers,

pub code_buf_dict_pos: usize,
pub lookahead_size: usize,
Expand All @@ -1214,7 +1214,7 @@ impl DictOxide {
fn new(flags: u32) -> Self {
DictOxide {
max_probes: probes_from_flags(flags),
b: Box::default(),
b: HashBuffers::default(),
code_buf_dict_pos: 0,
lookahead_size: 0,
lookahead_pos: 0,
Expand Down

0 comments on commit 60ed8cb

Please sign in to comment.