feat(compress): move match-state copies into Rust

Move the remaining CCtx and CDict copy match-state payloads into Rust. The
Rust bridges now copy the window projection, nextToUpdate, and loadedDictEnd
fields directly after the existing reset and table callbacks. C retains the
private context layout, workspace ownership, and table-copy arithmetic.

Test Plan:
- ulimit -v 41943040 cargo fmt --manifest-path rust/Cargo.toml -- --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
- 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
This commit is contained in:
2026-07-19 22:48:30 +02:00
parent 4117ec7b3e
commit 7eb70baec1
3 changed files with 248 additions and 65 deletions
+37 -31
View File
@@ -479,7 +479,12 @@ typedef struct {
ZSTD_rust_copyCCtxMarkTables_f markTablesDirty;
ZSTD_rust_copyCCtxCopyTables_f copyTables;
ZSTD_rust_copyCCtxMarkTables_f markTablesClean;
ZSTD_rust_copyCCtxCopyState_f copyMatchState;
void* destinationWindow;
const void* sourceWindow;
U32* destinationNextToUpdate;
const U32* sourceNextToUpdate;
U32* destinationLoadedDictEnd;
const U32* sourceLoadedDictEnd;
U32* destinationDictID;
const U32* sourceDictID;
size_t* destinationDictContentSize;
@@ -488,6 +493,11 @@ typedef struct {
const ZSTD_compressedBlockState_t* sourceBlockState;
int zbuff;
} ZSTD_rust_copyCCtxInternalState;
typedef char ZSTD_rust_copy_window_state_layout[
sizeof(ZSTD_window_t)
== ((3 * sizeof(void*) + 3 * sizeof(U32) + sizeof(void*) - 1)
/ sizeof(void*)) * sizeof(void*)
? 1 : -1];
size_t ZSTD_rust_copyCCtxInternal(
const ZSTD_rust_copyCCtxInternalState* state);
typedef size_t (*ZSTD_rust_copyCCtxInternal_f)(
@@ -526,7 +536,7 @@ typedef char ZSTD_rust_copy_cctx_internal_state_layout[
== 3 * sizeof(void*) + sizeof(U64)
&& offsetof(ZSTD_rust_copyCCtxInternalState, zbuff)
== 3 * sizeof(void*) + sizeof(U64)
+ 13 * sizeof(void*)
+ 18 * sizeof(void*)
&& sizeof(ZSTD_rust_copyCCtxInternalState)
== ((offsetof(ZSTD_rust_copyCCtxInternalState, zbuff)
+ sizeof(int) + sizeof(void*) - 1) / sizeof(void*))
@@ -2499,7 +2509,12 @@ typedef struct {
ZSTD_rust_resetCCtxByCopyingCDictState_f copyTables;
ZSTD_rust_resetCCtxByCopyingCDictState_f zeroHashTable3;
ZSTD_rust_resetCCtxByCopyingCDictMarkTables_f markTablesClean;
ZSTD_rust_resetCCtxByCopyingCDictState_f copyMatchState;
void* destinationWindow;
const void* sourceWindow;
U32* destinationNextToUpdate;
const U32* sourceNextToUpdate;
U32* destinationLoadedDictEnd;
const U32* sourceLoadedDictEnd;
U32* destinationDictID;
const U32* sourceDictID;
size_t* destinationDictContentSize;
@@ -2521,7 +2536,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) + 12 * sizeof(void*)
== 3 * sizeof(void*) + sizeof(U64) + 17 * sizeof(void*)
&& sizeof(ZSTD_rust_resetCCtxByCopyingCDictState)
== ((offsetof(ZSTD_rust_resetCCtxByCopyingCDictState, zbuff)
+ sizeof(int) + sizeof(void*) - 1) / sizeof(void*))
@@ -4642,18 +4657,6 @@ static void ZSTD_rust_resetCCtx_byCopyingCDict_mark_tables_clean(void* context)
ZSTD_cwksp_mark_tables_clean(&cctx->workspace);
}
static void ZSTD_rust_resetCCtx_byCopyingCDict_copy_match_state(
void* context, const void* cdictOpaque)
{
ZSTD_CCtx* const cctx = (ZSTD_CCtx*)context;
const ZSTD_CDict* const cdict = (const ZSTD_CDict*)cdictOpaque;
const ZSTD_MatchState_t* const src = &cdict->matchState;
ZSTD_MatchState_t* const dst = &cctx->blockState.matchState;
dst->window = src->window;
dst->nextToUpdate = src->nextToUpdate;
dst->loadedDictEnd = src->loadedDictEnd;
}
static size_t ZSTD_resetCCtx_byCopyingCDict(ZSTD_CCtx* cctx,
const ZSTD_CDict* cdict,
ZSTD_CCtx_params params,
@@ -4673,8 +4676,12 @@ static size_t ZSTD_resetCCtx_byCopyingCDict(ZSTD_CCtx* cctx,
ZSTD_rust_resetCCtx_byCopyingCDict_zero_hash_table3;
state.markTablesClean =
ZSTD_rust_resetCCtx_byCopyingCDict_mark_tables_clean;
state.copyMatchState =
ZSTD_rust_resetCCtx_byCopyingCDict_copy_match_state;
state.destinationWindow = &cctx->blockState.matchState.window;
state.sourceWindow = &cdict->matchState.window;
state.destinationNextToUpdate = &cctx->blockState.matchState.nextToUpdate;
state.sourceNextToUpdate = &cdict->matchState.nextToUpdate;
state.destinationLoadedDictEnd = &cctx->blockState.matchState.loadedDictEnd;
state.sourceLoadedDictEnd = &cdict->matchState.loadedDictEnd;
state.destinationDictID = &cctx->dictID;
state.sourceDictID = &cdict->dictID;
state.destinationDictContentSize = &cctx->dictContentSize;
@@ -4828,18 +4835,6 @@ static void ZSTD_rust_copyCCtx_mark_tables_clean(void* context)
ZSTD_cwksp_mark_tables_clean(&dst->workspace);
}
static void ZSTD_rust_copyCCtx_copy_match_state(
void* context, const void* srcCCtx)
{
ZSTD_CCtx* const dst = (ZSTD_CCtx*)context;
const ZSTD_CCtx* const src = (const ZSTD_CCtx*)srcCCtx;
const ZSTD_MatchState_t* const srcMatchState = &src->blockState.matchState;
ZSTD_MatchState_t* const dstMatchState = &dst->blockState.matchState;
dstMatchState->window = srcMatchState->window;
dstMatchState->nextToUpdate = srcMatchState->nextToUpdate;
dstMatchState->loadedDictEnd = srcMatchState->loadedDictEnd;
}
static size_t ZSTD_rust_copyCCtx_internal_callback(
void* context, const void* srcCCtx,
const ZSTD_frameParameters* fParams,
@@ -4856,7 +4851,18 @@ static size_t ZSTD_rust_copyCCtx_internal_callback(
state.markTablesDirty = ZSTD_rust_copyCCtx_mark_tables_dirty;
state.copyTables = ZSTD_rust_copyCCtx_copy_tables;
state.markTablesClean = ZSTD_rust_copyCCtx_mark_tables_clean;
state.copyMatchState = ZSTD_rust_copyCCtx_copy_match_state;
state.destinationWindow =
&((ZSTD_CCtx*)context)->blockState.matchState.window;
state.sourceWindow =
&((const ZSTD_CCtx*)srcCCtx)->blockState.matchState.window;
state.destinationNextToUpdate =
&((ZSTD_CCtx*)context)->blockState.matchState.nextToUpdate;
state.sourceNextToUpdate =
&((const ZSTD_CCtx*)srcCCtx)->blockState.matchState.nextToUpdate;
state.destinationLoadedDictEnd =
&((ZSTD_CCtx*)context)->blockState.matchState.loadedDictEnd;
state.sourceLoadedDictEnd =
&((const ZSTD_CCtx*)srcCCtx)->blockState.matchState.loadedDictEnd;
state.destinationDictID = &((ZSTD_CCtx*)context)->dictID;
state.sourceDictID = &((const ZSTD_CCtx*)srcCCtx)->dictID;
state.destinationDictContentSize = &((ZSTD_CCtx*)context)->dictContentSize;