refactor(compress): move stream fast-path policy to Rust
Project the private stream state needed by the complete-input streaming fast path into a stable C/Rust layout and let Rust own the eligibility predicate. The C bridge keeps the CCtx private and retains the existing simple-level selection leaf as a callback, while focused tests cover the accepted and rejected stream states. All heavy verification was run serially with a 40 GiB virtual-memory cap and one build job. Test Plan: - git diff --cached --check - ulimit -v 41943040; CARGO_BUILD_JOBS=1 cargo clippy --manifest-path rust/Cargo.toml --all-targets -- -D warnings - ulimit -v 41943040; CARGO_BUILD_JOBS=1 cargo test --manifest-path rust/Cargo.toml --all-targets (788 passed) - ulimit -v 41943040; CARGO_BUILD_JOBS=1 cargo clippy --manifest-path rust/cli/Cargo.toml --all-targets -- -D warnings - ulimit -v 41943040; CARGO_BUILD_JOBS=1 cargo test --manifest-path rust/cli/Cargo.toml --all-targets (181 passed) - ulimit -v 41943040; cargo +nightly fmt --manifest-path rust/Cargo.toml --all -- --check - ulimit -v 41943040; make -j1 - ulimit -v 41943040; make -j1 -C tests test
This commit is contained in:
@@ -731,6 +731,25 @@ size_t ZSTD_compressStream2_c(ZSTD_CCtx* cctx,
|
||||
ZSTD_inBuffer* input,
|
||||
ZSTD_EndDirective endOp);
|
||||
int ZSTD_rust_simpleCompress2Level(const void* cctx, size_t srcSize);
|
||||
typedef int (*ZSTD_rust_simpleCompress2Level_f)(const void* cctx, size_t srcSize);
|
||||
typedef struct {
|
||||
int streamStage;
|
||||
unsigned long long pledgedSrcSizePlusOne;
|
||||
unsigned rustSimpleCompress2Completed;
|
||||
} ZSTD_rust_simpleCompressStream2Projection;
|
||||
typedef char ZSTD_rust_simple_compress_stream2_projection_layout[
|
||||
(offsetof(ZSTD_rust_simpleCompressStream2Projection, streamStage) == 0
|
||||
&& offsetof(ZSTD_rust_simpleCompressStream2Projection, pledgedSrcSizePlusOne)
|
||||
== (sizeof(void*) == 8 ? 8 : 4)
|
||||
&& offsetof(ZSTD_rust_simpleCompressStream2Projection,
|
||||
rustSimpleCompress2Completed)
|
||||
== (sizeof(void*) == 8 ? 16 : 12)
|
||||
&& sizeof(ZSTD_rust_simpleCompressStream2Projection)
|
||||
== (sizeof(void*) == 8 ? 24 : 16)) ? 1 : -1];
|
||||
int ZSTD_rust_simpleCompressStream2Policy(
|
||||
const ZSTD_rust_simpleCompressStream2Projection* projection,
|
||||
const void* cctx, size_t srcSize,
|
||||
ZSTD_rust_simpleCompress2Level_f simpleCompress2Level);
|
||||
int ZSTD_rust_simpleCompressStream2Level(const void* cctx, size_t srcSize);
|
||||
U32 ZSTD_rust_limitNextToUpdate(U32 curr, U32 nextToUpdate);
|
||||
void ZSTD_rust_advanceHashSaltInPlace(U64* hashSalt, U64 hashSaltEntropy);
|
||||
@@ -6888,13 +6907,13 @@ int ZSTD_rust_simpleCompress2Level(const void* opaqueCctx, size_t srcSize)
|
||||
int ZSTD_rust_simpleCompressStream2Level(const void* opaqueCctx, size_t srcSize)
|
||||
{
|
||||
ZSTD_CCtx const* const cctx = (ZSTD_CCtx const*)opaqueCctx;
|
||||
if (cctx == NULL
|
||||
|| cctx->streamStage != zcss_init
|
||||
|| cctx->pledgedSrcSizePlusOne != 0
|
||||
|| cctx->rustSimpleCompress2Completed != 0) {
|
||||
return (-2147483647 - 1);
|
||||
}
|
||||
return ZSTD_rust_simpleCompress2Level(opaqueCctx, srcSize);
|
||||
ZSTD_rust_simpleCompressStream2Projection const projection = {
|
||||
cctx == NULL ? 0 : (int)cctx->streamStage,
|
||||
cctx == NULL ? 0 : cctx->pledgedSrcSizePlusOne,
|
||||
cctx == NULL ? 0 : cctx->rustSimpleCompress2Completed
|
||||
};
|
||||
return ZSTD_rust_simpleCompressStream2Policy(
|
||||
&projection, opaqueCctx, srcSize, ZSTD_rust_simpleCompress2Level);
|
||||
}
|
||||
|
||||
/* ZSTD_compress() is implemented by rust/src/zstd_compress.rs. */
|
||||
|
||||
Reference in New Issue
Block a user