-
-
Notifications
You must be signed in to change notification settings - Fork 11
More initialization cleanup #390
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
16c6a90
Clean up `ZSTD_inBuffer` and `ZSTD_outBuffer` initialization
michielp1807 7612084
Clean up `HUF_CStream_t` initialization
michielp1807 4e623cc
Clean up `BIT_DStream_t` initialization
michielp1807 f06ac7f
Use default to initialize `ZSTD_entropyCTablesMetadata_t`
michielp1807 330882e
Clean up `ldmEntry_t` initialization
michielp1807 d77edb5
`ZSTD_opt_getNextMatchAndUpdateSeqStore`: clean up variables
michielp1807 5acdc42
Use default to initialize `ZSTDv0{5,6}_parameters`
michielp1807 93f3138
Clean up `COVER_segment_t` initialization
michielp1807 947d214
Clean up `COVER_computeEpochs`
michielp1807 d29dd71
Use default to initialize `ZSTD_CCtx_s`
michielp1807 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 |
|---|---|---|
| @@ -1,5 +1,4 @@ | ||
| use core::ffi::{c_int, c_uint, c_void}; | ||
| use core::ptr; | ||
|
|
||
| use libc::size_t; | ||
|
|
||
|
|
@@ -1020,28 +1019,23 @@ pub struct HUF_CStream_t { | |
| pub endPtr: *mut u8, | ||
| } | ||
|
|
||
| /// Initializes the bitstream. | ||
| /// | ||
| /// # Returns | ||
| /// | ||
| /// 0 or an error code. | ||
| unsafe fn HUF_initCStream( | ||
| bitC: &mut HUF_CStream_t, | ||
| startPtr: *mut c_void, | ||
| dstCapacity: size_t, | ||
| ) -> size_t { | ||
| ptr::write_bytes( | ||
| ptr::from_mut(bitC).cast::<u8>(), | ||
| 0, | ||
| size_of::<HUF_CStream_t>(), | ||
| ); | ||
| bitC.startPtr = startPtr as *mut u8; | ||
| bitC.ptr = bitC.startPtr; | ||
| bitC.endPtr = (bitC.startPtr).add(dstCapacity).sub(size_of::<size_t>()); | ||
| if dstCapacity <= size_of::<size_t>() { | ||
| return Error::dstSize_tooSmall.to_error_code(); | ||
| impl HUF_CStream_t { | ||
| pub unsafe fn new(startPtr: *mut c_void, dstCapacity: size_t) -> Result<Self, Error> { | ||
| if dstCapacity <= size_of::<size_t>() { | ||
| return Err(Error::dstSize_tooSmall); | ||
| } | ||
|
|
||
| let startPtr = startPtr as *mut u8; | ||
| let endPtr = startPtr.add(dstCapacity).sub(size_of::<size_t>()); | ||
|
|
||
| Ok(HUF_CStream_t { | ||
| bitContainer: [0; 2], | ||
| bitPos: [0; 2], | ||
| startPtr, | ||
| ptr: startPtr, | ||
| endPtr, | ||
| }) | ||
| } | ||
| 0 | ||
| } | ||
|
|
||
| /// Adds the symbol stored in HUF_CElt elt to the bitstream. | ||
|
|
@@ -1270,27 +1264,16 @@ unsafe fn HUF_compress1X_usingCTable_internal_body( | |
| let tableLog = CTable.header.tableLog as u32; | ||
| let ct = &CTable.elements; | ||
| let ip = src as *const u8; | ||
| let ostart = dst as *mut u8; | ||
| let oend = ostart.add(dstSize); | ||
| let mut bitC = HUF_CStream_t { | ||
| bitContainer: [0; 2], | ||
| bitPos: [0; 2], | ||
| startPtr: core::ptr::null_mut::<u8>(), | ||
| ptr: core::ptr::null_mut::<u8>(), | ||
| endPtr: core::ptr::null_mut::<u8>(), | ||
| }; | ||
|
|
||
| /* init */ | ||
| if dstSize < 8 { | ||
| return 0; /* not enough space to compress */ | ||
| } | ||
| { | ||
| let op = ostart; | ||
| let initErr = HUF_initCStream(&mut bitC, op as *mut c_void, oend.offset_from_unsigned(op)); | ||
| if ERR_isError(initErr) { | ||
| return 0; | ||
| } | ||
| } | ||
|
|
||
| let mut bitC = match HUF_CStream_t::new(dst, dstSize) { | ||
| Ok(bitC) => bitC, | ||
| Err(_) => return 0, | ||
| }; | ||
|
Comment on lines
+1273
to
+1276
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. shorter as let-else |
||
|
|
||
| if dstSize < HUF_tightCompressBound(srcSize, tableLog as size_t) || tableLog > 11 { | ||
| HUF_compress1X_usingCTable_internal_body_loop( | ||
|
|
||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
This could be safe with
wrapping_{add ,sub}