feat(compress): move long-match update arithmetic into Rust

Move the bounded nextToUpdate catch-up arithmetic used after very long
matches into Rust. C continues to calculate the source index against the
private match-state window and retains all surrounding assertions and setup;
Rust owns the exact wrapping U32 threshold and 192-byte catch-up policy.

Test Plan:
- cargo fmt --manifest-path rust/Cargo.toml -- --check
- ulimit -v 41943040 && CARGO_BUILD_JOBS=1 cargo test --manifest-path rust/Cargo.toml limit_next_to_update --lib (1 passed)
- ulimit -v 41943040 && CARGO_BUILD_JOBS=1 cargo test --manifest-path rust/Cargo.toml --lib (692 passed)
- ulimit -v 41943040 && CARGO_BUILD_JOBS=1 cargo clippy --manifest-path rust/Cargo.toml --all-targets -- -D warnings
- ulimit -v 41943040 && MAKEFLAGS=-j1 make -B -C programs -j1 zstd
- ulimit -v 41943040 && MAKEFLAGS=-j1 make -C tests -j1 test-zstream ZSTREAM_TESTTIME=-T1s (84 tests and both short fuzz rounds passed)
This commit is contained in:
2026-07-19 19:08:13 +02:00
parent e95778be1a
commit bff97833b6
2 changed files with 31 additions and 2 deletions
+2 -2
View File
@@ -604,6 +604,7 @@ size_t ZSTD_compressStream2_c(ZSTD_CCtx* cctx,
ZSTD_EndDirective endOp);
int ZSTD_rust_simpleCompress2Level(const void* cctx, size_t srcSize);
int ZSTD_rust_simpleCompressStream2Level(const void* cctx, size_t srcSize);
U32 ZSTD_rust_limitNextToUpdate(U32 curr, U32 nextToUpdate);
void ZSTD_rust_reduceIndex(U32* hashTable, U32 hashSize,
U32* chainTable, U32 chainSize,
U32* hashTable3, U32 hashSize3,
@@ -4721,8 +4722,7 @@ static void ZSTD_rust_buildSeqStore_prepareMatchState(void* context,
const BYTE* const istart = (const BYTE*)src;
const U32 curr = (U32)(istart-base);
if (sizeof(ptrdiff_t)==8) assert(istart - base < (ptrdiff_t)(U32)(-1));
if (curr > ms->nextToUpdate + 384)
ms->nextToUpdate = curr - MIN(192, (U32)(curr - ms->nextToUpdate - 384));
ms->nextToUpdate = ZSTD_rust_limitNextToUpdate(curr, ms->nextToUpdate);
}
}