feat(compress): move workspace size aggregation to Rust
Keep all context-sensitive workspace sizing in C, including intermediate allocation calculations, match-state and LDM sizing, error propagation, and diagnostics. Move only the final nine-component neededSpace aggregation behind a scalar Rust ABI helper so its size_t wrapping behavior is explicit and independently tested. Test Plan: - `cargo clippy --manifest-path rust/Cargo.toml --no-default-features --features compression` -- passed before and after formatting. - The same command with `--benches` and `--tests` -- passed before and after formatting. - `cargo +nightly fmt --manifest-path rust/Cargo.toml` -- passed. - `cargo test --manifest-path rust/Cargo.toml --no-default-features --features compression zstd_compress` -- 186 passed. - `make -B -C lib -j2 lib` -- passed. - `make -C tests test-rust-lib-smoke` -- passed. - `tests/fuzzer -s4560 -t56 -i57 -v` -- passed. - `make -C tests -j2 test-zstream` -- 84 named tests and 6,536 plus 7,961 randomized cases passed; the existing unterminated-string warning remains. - `git diff --cached --check` -- passed.
This commit is contained in:
@@ -92,6 +92,15 @@ size_t ZSTD_rust_sizeofLocalDict(int dictBufferPresent, size_t dictSize,
|
||||
size_t cdictSize);
|
||||
size_t ZSTD_rust_sizeofCCtx(size_t objectSize, size_t workspaceSize,
|
||||
size_t localDictSize, size_t mtctxSize);
|
||||
size_t ZSTD_rust_estimateWorkspaceSize(size_t cctxSpace,
|
||||
size_t tmpWorkSpace,
|
||||
size_t blockStateSpace,
|
||||
size_t ldmSpace,
|
||||
size_t ldmSeqSpace,
|
||||
size_t matchStateSize,
|
||||
size_t tokenSpace,
|
||||
size_t bufferSpace,
|
||||
size_t externalSeqSpace);
|
||||
ZSTD_inBuffer ZSTD_rust_inBufferForEndFlush(int inBufferMode,
|
||||
const void* expectedSrc,
|
||||
size_t expectedSize,
|
||||
@@ -1284,16 +1293,9 @@ static size_t ZSTD_estimateCCtxSize_usingCCtxParams_internal(
|
||||
? ZSTD_cwksp_aligned64_alloc_size(maxNbExternalSeq * sizeof(ZSTD_Sequence))
|
||||
: 0;
|
||||
|
||||
size_t const neededSpace =
|
||||
cctxSpace +
|
||||
tmpWorkSpace +
|
||||
blockStateSpace +
|
||||
ldmSpace +
|
||||
ldmSeqSpace +
|
||||
matchStateSize +
|
||||
tokenSpace +
|
||||
bufferSpace +
|
||||
externalSeqSpace;
|
||||
size_t const neededSpace = ZSTD_rust_estimateWorkspaceSize(
|
||||
cctxSpace, tmpWorkSpace, blockStateSpace, ldmSpace, ldmSeqSpace,
|
||||
matchStateSize, tokenSpace, bufferSpace, externalSeqSpace);
|
||||
|
||||
DEBUGLOG(5, "estimate workspace : %u", (U32)neededSpace);
|
||||
return neededSpace;
|
||||
|
||||
Reference in New Issue
Block a user