feat(compress): move match-state salt update into Rust

Move the row-matchfinder hash-salt field update behind a Rust in-place leaf.
C retains the private match-state pointer and entropy field access, while Rust
owns the scalar mutation and reuses the tested salt arithmetic.

Test Plan:
- 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 zstd_compress::tests::bitmix_and_hash_salt_match_the_c_arithmetic -- --nocapture
- ulimit -v 41943040 && make -j1
- ulimit -v 41943040 && make -j1 -C tests test-fuzzer FUZZERTEST=-T3s FUZZER_FLAGS=--no-big-tests
This commit is contained in:
2026-07-19 21:08:02 +02:00
parent 481a53baf8
commit 2d2214eb1d
2 changed files with 19 additions and 5 deletions
+16
View File
@@ -5599,6 +5599,19 @@ pub extern "C" fn ZSTD_rust_advanceHashSalt(hash_salt: u64, hash_salt_entropy: u
advance_hash_salt(hash_salt, hash_salt_entropy)
}
/// Advance a C-owned row-matchfinder salt in place while C retains the
/// private match-state layout.
#[no_mangle]
pub unsafe extern "C" fn ZSTD_rust_advanceHashSaltInPlace(
hash_salt: *mut u64,
hash_salt_entropy: u64,
) {
debug_assert!(!hash_salt.is_null());
unsafe {
*hash_salt = advance_hash_salt(*hash_salt, hash_salt_entropy);
}
}
#[inline]
fn index_too_close_to_max(next_src_base_offset: usize) -> bool {
next_src_base_offset > ZSTD_CURRENT_MAX - ZSTD_INDEXOVERFLOW_MARGIN
@@ -11243,6 +11256,9 @@ mod tests {
ZSTD_rust_advanceHashSalt(0x0123_4567_89ab_cdef, 0xfedc_ba98_7654_3210),
0xe5ee_f172_e5ff_3e57
);
let mut hash_salt = 0x0123_4567_89ab_cdef;
unsafe { ZSTD_rust_advanceHashSaltInPlace(&mut hash_salt, 0xfedc_ba98_7654_3210) };
assert_eq!(hash_salt, 0xe5ee_f172_e5ff_3e57);
}
#[test]