feat(compress): move next input hint policy to Rust

Keep ZSTD_nextInputSizeHint's C-owned state-machine and MT routing while
moving its mode-dependent arithmetic behind a narrow scalar ABI. Rust now
receives the buffer mode and four size fields, preserving stable-buffer
capacity, buffered target remainder, and the zero-remainder block-size
fallback without exposing ZSTD_CCtx.

Test Plan:
- `cargo test --manifest-path rust/Cargo.toml --no-default-features --features compression next_input_size_hint` -- passed (3 tests)
- `make -B -C lib -j2 lib` -- passed
- `make -C tests -j2 fuzzer` and `./tests/fuzzer -s4560 -t47 -i48 -v` -- passed
- Required clippy, nightly fmt, and staged diff checks -- passed
This commit is contained in:
2026-07-18 09:33:36 +02:00
parent da84c8ff95
commit 527cf01031
2 changed files with 83 additions and 7 deletions
+18 -7
View File
@@ -79,6 +79,11 @@ int ZSTD_rust_targetCBlockSizeAction(int bss, int isFirstBlock,
int maybeRLE, int isRLE,
size_t cSize, size_t srcSize,
int strategy);
size_t ZSTD_rust_nextInputSizeHint(int inBufferMode,
size_t blockSizeMax,
size_t stableInNotConsumed,
size_t inBuffTarget,
size_t inBuffPos);
size_t ZSTD_rust_CStreamInSize(void);
size_t ZSTD_rust_CStreamOutSize(void);
@@ -4524,14 +4529,20 @@ size_t ZSTD_initCStream(ZSTD_CStream* zcs, int compressionLevel)
static size_t ZSTD_nextInputSizeHint(const ZSTD_CCtx* cctx)
{
if (cctx->appliedParams.inBufferMode == ZSTD_bm_stable) {
return cctx->blockSizeMax - cctx->stableIn_notConsumed;
}
assert(cctx->appliedParams.inBufferMode == ZSTD_bm_buffered);
{ size_t hintInSize = cctx->inBuffTarget - cctx->inBuffPos;
if (hintInSize==0) hintInSize = cctx->blockSizeMax;
return hintInSize;
int const inBufferMode = (int)cctx->appliedParams.inBufferMode;
if (inBufferMode == ZSTD_bm_stable) {
return ZSTD_rust_nextInputSizeHint(inBufferMode,
cctx->blockSizeMax,
cctx->stableIn_notConsumed,
cctx->inBuffTarget,
cctx->inBuffPos);
}
assert(inBufferMode == ZSTD_bm_buffered);
return ZSTD_rust_nextInputSizeHint(inBufferMode,
cctx->blockSizeMax,
cctx->stableIn_notConsumed,
cctx->inBuffTarget,
cctx->inBuffPos);
}
/** ZSTD_compressStream_generic():