diff --git a/miniz_oxide/src/deflate/buffer.rs b/miniz_oxide/src/deflate/buffer.rs index f246c07..e8b6b01 100644 --- a/miniz_oxide/src/deflate/buffer.rs +++ b/miniz_oxide/src/deflate/buffer.rs @@ -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. @@ -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, + pub next: Vec, + pub hash: Vec, } 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); } } diff --git a/miniz_oxide/src/deflate/core.rs b/miniz_oxide/src/deflate/core.rs index b0a532d..79cdeb4 100644 --- a/miniz_oxide/src/deflate/core.rs +++ b/miniz_oxide/src/deflate/core.rs @@ -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, + pub b: HashBuffers, pub code_buf_dict_pos: usize, pub lookahead_size: usize, @@ -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,