feat(compress): move CDict block-state copies into Rust

Pass the CCtx compressed-block-state pointer slot and CDict source state
through the attach/copy bridges, then perform the final state copy in Rust
after reset has established the destination. Remove the redundant C memcpy
adapters while preserving dictionary attach/copy ordering and null/error
behavior.

Add focused tests for copied repcodes and entropy repeat state.

Test Plan:
- ulimit -v 41943040 && CARGO_BUILD_JOBS=1 cargo test --manifest-path rust/Cargo.toml
- ulimit -v 41943040 && CARGO_BUILD_JOBS=1 cargo clippy --manifest-path rust/Cargo.toml --all-targets -- -D warnings
- ulimit -v 41943040 && make -j1
- ulimit -v 41943040 && make -j1 -C tests test-zstream ZSTREAM_TESTTIME=-T2s
- ulimit -v 41943040 && make -j1 -C tests test-fuzzer FUZZERTEST=-T3s FUZZER_FLAGS=--no-big-tests
- ulimit -v 41943040 && cargo fmt --manifest-path rust/Cargo.toml -- --check
- git diff --check
This commit is contained in:
2026-07-19 22:24:29 +02:00
parent 45191e1413
commit 8957ac786a
2 changed files with 118 additions and 68 deletions
+10 -25
View File
@@ -2497,7 +2497,8 @@ typedef struct {
ZSTD_rust_resetCCtxByCopyingCDictMarkTables_f markTablesClean;
ZSTD_rust_resetCCtxByCopyingCDictState_f copyMatchState;
ZSTD_rust_resetCCtxByCopyingCDictState_f copyDictState;
ZSTD_rust_resetCCtxByCopyingCDictState_f copyBlockState;
ZSTD_compressedBlockState_t** destinationBlockState;
const ZSTD_compressedBlockState_t* sourceBlockState;
int zbuff;
} ZSTD_rust_resetCCtxByCopyingCDictState;
size_t ZSTD_rust_resetCCtxByCopyingCDict(
@@ -2513,7 +2514,7 @@ typedef char ZSTD_rust_reset_cctx_by_copying_cdict_state_layout[
&& offsetof(ZSTD_rust_resetCCtxByCopyingCDictState, reset)
== 3 * sizeof(void*) + sizeof(U64)
&& offsetof(ZSTD_rust_resetCCtxByCopyingCDictState, zbuff)
== 3 * sizeof(void*) + sizeof(U64) + 8 * sizeof(void*)
== 3 * sizeof(void*) + sizeof(U64) + 9 * sizeof(void*)
&& sizeof(ZSTD_rust_resetCCtxByCopyingCDictState)
== ((offsetof(ZSTD_rust_resetCCtxByCopyingCDictState, zbuff)
+ sizeof(int) + sizeof(void*) - 1) / sizeof(void*))
@@ -2534,7 +2535,8 @@ typedef struct {
ZSTD_rust_resetCCtxByAttachingCDictReset_f reset;
ZSTD_rust_resetCCtxByAttachingCDictAttach_f attach;
ZSTD_rust_resetCCtxByAttachingCDictState_f copyDictState;
ZSTD_rust_resetCCtxByAttachingCDictState_f copyBlockState;
ZSTD_compressedBlockState_t** destinationBlockState;
const ZSTD_compressedBlockState_t* sourceBlockState;
int zbuff;
} ZSTD_rust_resetCCtxByAttachingCDictState;
size_t ZSTD_rust_resetCCtxByAttachingCDict(
@@ -2550,7 +2552,7 @@ typedef char ZSTD_rust_reset_cctx_by_attaching_cdict_state_layout[
&& offsetof(ZSTD_rust_resetCCtxByAttachingCDictState, reset)
== 3 * sizeof(void*) + sizeof(U64)
&& offsetof(ZSTD_rust_resetCCtxByAttachingCDictState, zbuff)
== 3 * sizeof(void*) + sizeof(U64) + 4 * sizeof(void*)
== 3 * sizeof(void*) + sizeof(U64) + 5 * sizeof(void*)
&& sizeof(ZSTD_rust_resetCCtxByAttachingCDictState)
== ((offsetof(ZSTD_rust_resetCCtxByAttachingCDictState, zbuff)
+ sizeof(int) + sizeof(void*) - 1) / sizeof(void*))
@@ -4518,15 +4520,6 @@ static void ZSTD_rust_resetCCtx_byAttachingCDict_copy_dict_state(
cctx->dictContentSize = cdict->dictContentSize;
}
static void ZSTD_rust_resetCCtx_byAttachingCDict_copy_block_state(
void* context, const void* cdictOpaque)
{
ZSTD_CCtx* const cctx = (ZSTD_CCtx*)context;
const ZSTD_CDict* const cdict = (const ZSTD_CDict*)cdictOpaque;
ZSTD_memcpy(cctx->blockState.prevCBlock, &cdict->cBlockState,
sizeof(cdict->cBlockState));
}
static size_t
ZSTD_resetCCtx_byAttachingCDict(ZSTD_CCtx* cctx,
const ZSTD_CDict* cdict,
@@ -4542,7 +4535,8 @@ ZSTD_resetCCtx_byAttachingCDict(ZSTD_CCtx* cctx,
state.reset = ZSTD_rust_resetCCtx_byAttachingCDict_reset;
state.attach = ZSTD_rust_resetCCtx_byAttachingCDict_attach;
state.copyDictState = ZSTD_rust_resetCCtx_byAttachingCDict_copy_dict_state;
state.copyBlockState = ZSTD_rust_resetCCtx_byAttachingCDict_copy_block_state;
state.destinationBlockState = &cctx->blockState.prevCBlock;
state.sourceBlockState = &cdict->cBlockState;
state.zbuff = (int)zbuff;
return ZSTD_rust_resetCCtxByAttachingCDict(&state);
}
@@ -4667,15 +4661,6 @@ static void ZSTD_rust_resetCCtx_byCopyingCDict_copy_dict_state(
cctx->dictContentSize = cdict->dictContentSize;
}
static void ZSTD_rust_resetCCtx_byCopyingCDict_copy_block_state(
void* context, const void* cdictOpaque)
{
ZSTD_CCtx* const cctx = (ZSTD_CCtx*)context;
const ZSTD_CDict* const cdict = (const ZSTD_CDict*)cdictOpaque;
ZSTD_memcpy(cctx->blockState.prevCBlock, &cdict->cBlockState,
sizeof(cdict->cBlockState));
}
static size_t ZSTD_resetCCtx_byCopyingCDict(ZSTD_CCtx* cctx,
const ZSTD_CDict* cdict,
ZSTD_CCtx_params params,
@@ -4699,8 +4684,8 @@ static size_t ZSTD_resetCCtx_byCopyingCDict(ZSTD_CCtx* cctx,
ZSTD_rust_resetCCtx_byCopyingCDict_copy_match_state;
state.copyDictState =
ZSTD_rust_resetCCtx_byCopyingCDict_copy_dict_state;
state.copyBlockState =
ZSTD_rust_resetCCtx_byCopyingCDict_copy_block_state;
state.destinationBlockState = &cctx->blockState.prevCBlock;
state.sourceBlockState = &cdict->cBlockState;
state.zbuff = (int)zbuff;
return ZSTD_rust_resetCCtxByCopyingCDict(&state);
}