Skip to content

Commit 474a498

Browse files
committed
Adjust Strategy in CParams to Avoid Using Excluded Block Compressors
1 parent 6df288d commit 474a498

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

lib/compress/zstd_compress.c

+44
Original file line numberDiff line numberDiff line change
@@ -1467,6 +1467,50 @@ ZSTD_adjustCParams_internal(ZSTD_compressionParameters cPar,
14671467
const U64 maxWindowResize = 1ULL << (ZSTD_WINDOWLOG_MAX-1);
14681468
assert(ZSTD_checkCParams(cPar)==0);
14691469

1470+
/* Cascade the selected strategy down to the next-highest one built into
1471+
* this binary. */
1472+
#if ZSTD_EXCLUDE_BTULTRA2_BLOCK_COMPRESSOR
1473+
if (cPar.strategy == ZSTD_btultra2) {
1474+
cPar.strategy = ZSTD_btultra;
1475+
}
1476+
#endif
1477+
#if ZSTD_EXCLUDE_BTULTRA_BLOCK_COMPRESSOR
1478+
if (cPar.strategy == ZSTD_btultra) {
1479+
cPar.strategy = ZSTD_btopt;
1480+
}
1481+
#endif
1482+
#if ZSTD_EXCLUDE_BTOPT_BLOCK_COMPRESSOR
1483+
if (cPar.strategy == ZSTD_btopt) {
1484+
cPar.strategy = ZSTD_btlazy2;
1485+
}
1486+
#endif
1487+
#if ZSTD_EXCLUDE_BTLAZY2_BLOCK_COMPRESSOR
1488+
if (cPar.strategy == ZSTD_btlazy2) {
1489+
cPar.strategy = ZSTD_lazy2;
1490+
}
1491+
#endif
1492+
#if ZSTD_EXCLUDE_LAZY2_BLOCK_COMPRESSOR
1493+
if (cPar.strategy == ZSTD_lazy2) {
1494+
cPar.strategy = ZSTD_lazy;
1495+
}
1496+
#endif
1497+
#if ZSTD_EXCLUDE_LAZY_BLOCK_COMPRESSOR
1498+
if (cPar.strategy == ZSTD_lazy) {
1499+
cPar.strategy = ZSTD_greedy;
1500+
}
1501+
#endif
1502+
#if ZSTD_EXCLUDE_GREEDY_BLOCK_COMPRESSOR
1503+
if (cPar.strategy == ZSTD_greedy) {
1504+
cPar.strategy = ZSTD_dfast;
1505+
}
1506+
#endif
1507+
#if ZSTD_EXCLUDE_DFAST_BLOCK_COMPRESSOR
1508+
if (cPar.strategy == ZSTD_dfast) {
1509+
cPar.strategy = ZSTD_fast;
1510+
cPar.targetLength = 0;
1511+
}
1512+
#endif
1513+
14701514
switch (mode) {
14711515
case ZSTD_cpm_unknown:
14721516
case ZSTD_cpm_noAttachDict:

0 commit comments

Comments
 (0)