feat(compress): move block compressor index policy to Rust
Keep ZSTD_selectBlockCompressor's compressor tables, callback pointers, and final dictionary-mode table lookup in C while moving only the scalar choice of row-based versus ordinary table index to the Rust parameter-policy module. The Rust helper reuses the existing row-matchfinder policy, returns 0..2 for row entries, and returns 3 plus the strategy for ordinary entries. C retains its public/internal signature, strategy and row-mode assertions, numeric fast strategy assumption, and all private callback ownership. Test Plan: - Rust clippy normal, benches, and tests before and after nightly formatting -- passed. - `cargo test --manifest-path rust/Cargo.toml --no-default-features --features compression zstd_compress_params` -- 41 passed. - `make -B -C lib -j2 lib` -- passed without new warnings. - `make -C tests test-rust-lib-smoke` -- passed. - `tests/fuzzer -s4560 -t47 -i48 -v` and `-s4560 -t56 -i57 -v` -- passed. - `make -C tests -j2 test-zstream` -- 84 named tests plus 6,708 and 8,980 randomized cases passed. - `git diff --check` and `git diff --cached --check` -- passed. - The pre-existing `tests/zstreamtest.c:1899` unterminated-string warning remains.
This commit is contained in:
@@ -140,6 +140,7 @@ void ZSTD_rust_params_overrideCParams(ZSTD_compressionParameters* cParams,
|
||||
int ZSTD_rust_params_resolveExternalSequenceValidation(int mode);
|
||||
int ZSTD_rust_params_rowMatchFinderSupported(int strategy);
|
||||
int ZSTD_rust_params_rowMatchFinderUsed(int strategy, int mode);
|
||||
int ZSTD_rust_params_selectBlockCompressor(int strategy, int mode);
|
||||
int ZSTD_rust_params_resolveRowMatchFinderMode(
|
||||
int mode, ZSTD_compressionParameters cParams);
|
||||
int ZSTD_rust_params_resolveBlockSplitterMode(
|
||||
@@ -2265,11 +2266,14 @@ ZSTD_BlockCompressor_f ZSTD_selectBlockCompressor(ZSTD_strategy strat, ZSTD_Para
|
||||
NULL }
|
||||
};
|
||||
ZSTD_BlockCompressor_f selectedCompressor;
|
||||
int selectedCompressorIndex;
|
||||
ZSTD_STATIC_ASSERT((unsigned)ZSTD_fast == 1);
|
||||
|
||||
assert(ZSTD_cParam_withinBounds(ZSTD_c_strategy, (int)strat));
|
||||
DEBUGLOG(5, "Selected block compressor: dictMode=%d strat=%d rowMatchfinder=%d", (int)dictMode, (int)strat, (int)useRowMatchFinder);
|
||||
if (ZSTD_rowMatchFinderUsed(strat, useRowMatchFinder)) {
|
||||
selectedCompressorIndex = ZSTD_rust_params_selectBlockCompressor(
|
||||
(int)strat, (int)useRowMatchFinder);
|
||||
if (selectedCompressorIndex < 3) {
|
||||
static const ZSTD_BlockCompressor_f rowBasedBlockCompressors[4][3] = {
|
||||
{
|
||||
ZSTD_COMPRESSBLOCK_GREEDY_ROW,
|
||||
@@ -2294,9 +2298,9 @@ ZSTD_BlockCompressor_f ZSTD_selectBlockCompressor(ZSTD_strategy strat, ZSTD_Para
|
||||
};
|
||||
DEBUGLOG(5, "Selecting a row-based matchfinder");
|
||||
assert(useRowMatchFinder != ZSTD_ps_auto);
|
||||
selectedCompressor = rowBasedBlockCompressors[(int)dictMode][(int)strat - (int)ZSTD_greedy];
|
||||
selectedCompressor = rowBasedBlockCompressors[(int)dictMode][selectedCompressorIndex];
|
||||
} else {
|
||||
selectedCompressor = blockCompressor[(int)dictMode][(int)strat];
|
||||
selectedCompressor = blockCompressor[(int)dictMode][selectedCompressorIndex - 3];
|
||||
}
|
||||
assert(selectedCompressor != NULL);
|
||||
return selectedCompressor;
|
||||
|
||||
Reference in New Issue
Block a user