feat(compress): move CDict size aggregation to Rust
Keep ZSTD_sizeof_CDict's public behavior and workspace-sensitive layout accounting in C, while routing its final two-size_t addition through the Rust compression ABI. The Rust helper uses wrapping_add so its result matches C size_t arithmetic, including overflow. Test Plan: - `cargo clippy --manifest-path rust/Cargo.toml --no-default-features --features compression` -- passed before and after formatting - `cargo clippy --manifest-path rust/Cargo.toml --no-default-features --features compression --benches` -- passed before and after formatting - `cargo clippy --manifest-path rust/Cargo.toml --no-default-features --features compression --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 sizeof_cdict` -- 3 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, 6,809 and 9,613 randomized passed - `git diff --check` and `git diff --cached --check` -- passed
This commit is contained in:
@@ -88,6 +88,7 @@ size_t ZSTD_rust_nextInputSizeHint(int inBufferMode,
|
||||
size_t inBuffPos);
|
||||
size_t ZSTD_rust_CStreamInSize(void);
|
||||
size_t ZSTD_rust_CStreamOutSize(void);
|
||||
size_t ZSTD_rust_sizeofCDict(size_t objectSize, size_t workspaceSize);
|
||||
size_t ZSTD_rust_sizeofLocalDict(int dictBufferPresent, size_t dictSize,
|
||||
size_t cdictSize);
|
||||
size_t ZSTD_rust_sizeofCCtx(size_t objectSize, size_t workspaceSize,
|
||||
@@ -4000,11 +4001,13 @@ size_t ZSTD_estimateCDictSize(size_t dictSize, int compressionLevel)
|
||||
|
||||
size_t ZSTD_sizeof_CDict(const ZSTD_CDict* cdict)
|
||||
{
|
||||
size_t objectSize, workspaceSize;
|
||||
if (cdict==NULL) return 0; /* support sizeof on NULL */
|
||||
DEBUGLOG(5, "sizeof(*cdict) : %u", (unsigned)sizeof(*cdict));
|
||||
/* cdict may be in the workspace */
|
||||
return (cdict->workspace.workspace == cdict ? 0 : sizeof(*cdict))
|
||||
+ ZSTD_cwksp_sizeof(&cdict->workspace);
|
||||
objectSize = cdict->workspace.workspace == cdict ? 0 : sizeof(*cdict);
|
||||
workspaceSize = ZSTD_cwksp_sizeof(&cdict->workspace);
|
||||
return ZSTD_rust_sizeofCDict(objectSize, workspaceSize);
|
||||
}
|
||||
|
||||
static size_t ZSTD_initCDict_internal(
|
||||
|
||||
Reference in New Issue
Block a user