-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Box some stuff using the Box::default() trick to reduce stack usage
- Loading branch information
Showing
3 changed files
with
79 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
//! Buffer wrappers implementing default so we can allocate the buffers with `Box::default()` | ||
//! to avoid stack copies. Box::new() doesn't at the moment, and using a vec means we would lose | ||
//! static length info. | ||
use deflate::core::{LZ_DICT_SIZE, MAX_MATCH_LEN}; | ||
|
||
/// Size of the buffer of lz77 encoded data. | ||
pub const LZ_CODE_BUF_SIZE: usize = 64 * 1024; | ||
/// Size of the output buffer. | ||
pub const OUT_BUF_SIZE: usize = (LZ_CODE_BUF_SIZE * 13) / 10; | ||
|
||
pub struct HashBuffers { | ||
pub dict: [u8; LZ_DICT_SIZE + MAX_MATCH_LEN - 1 + 1], | ||
pub next: [u16; LZ_DICT_SIZE], | ||
pub hash: [u16; LZ_DICT_SIZE], | ||
} | ||
|
||
impl Default for HashBuffers { | ||
fn default() -> HashBuffers { | ||
HashBuffers { | ||
dict: [0; LZ_DICT_SIZE + MAX_MATCH_LEN - 1 + 1], | ||
next: [0; LZ_DICT_SIZE], | ||
hash: [0; LZ_DICT_SIZE], | ||
} | ||
} | ||
} | ||
|
||
pub struct LocalBuf { | ||
pub b: [u8; OUT_BUF_SIZE], | ||
} | ||
|
||
impl Default for LocalBuf { | ||
fn default() -> LocalBuf { | ||
LocalBuf { | ||
b: [0; OUT_BUF_SIZE] | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
f907ff7
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Gah it turns out I was a bit quick in committing this, getting random segfaults in when running test.sh. Did some more tinkering to make sure the Compressor struct is dropped properly, but that didn't solve it, so got to debug this some more tomorrow.
It's possibly related to allocating stuff with libc::alloc.