Skip to content

Commit 6b9e584

Browse files
committed
Detect LZ4 and ZSTD versions for compile-time function and symbol choice
1 parent 631e87f commit 6b9e584

File tree

1 file changed

+22
-26
lines changed

1 file changed

+22
-26
lines changed

groups/ntc/ntctlc/ntctlc_plugin.cpp

Lines changed: 22 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -822,34 +822,30 @@ ntsa::Error Lz4::deflateCreate()
822822
LZ4F_errorCode_t errorCode = 0;
823823
NTCCFG_WARNING_UNUSED(errorCode);
824824

825-
const int minLevel = 0;
826-
const int maxLevel = LZ4F_compressionLevel_max();
827-
828-
const int defaultLevel = 1;
829-
830825
if (d_config.goal().has_value()) {
831826
switch (d_config.goal().value()) {
832827
case ntca::CompressionGoal::e_BEST_SIZE:
833-
d_level = maxLevel;
828+
d_level = 12;
834829
break;
835830
case ntca::CompressionGoal::e_BETTER_SIZE:
836-
d_level = defaultLevel + bsl::abs((maxLevel - defaultLevel) / 2);
831+
d_level = 8;
837832
break;
838833
case ntca::CompressionGoal::e_BALANCED:
839-
d_level = defaultLevel;
834+
d_level = 3;
840835
break;
841836
case ntca::CompressionGoal::e_BETTER_SPEED:
842-
d_level = defaultLevel - bsl::abs((defaultLevel - minLevel) / 2);
837+
d_level = 2;
843838
break;
844839
case ntca::CompressionGoal::e_BEST_SPEED:
845-
d_level = minLevel;
840+
d_level = 1;
846841
break;
847842
default:
848843
break;
849844
}
850845
}
851846

852-
#if defined(LZ4F_STATIC_LINKING_ONLY)
847+
#if defined(LZ4F_STATIC_LINKING_ONLY) && \
848+
NTCTLC_PLUGIN_LZ4_VERSION_NUMBER >= NTCTLC_PLUGIN_LZ4_VERSION_MAKE(1, 9, 4)
853849

854850
LZ4F_CustomMem memoryManager;
855851
bsl::memset(&memoryManager, 0, sizeof memoryManager);
@@ -1224,7 +1220,8 @@ ntsa::Error Lz4::inflateCreate()
12241220
LZ4F_errorCode_t errorCode = 0;
12251221
NTCCFG_WARNING_UNUSED(errorCode);
12261222

1227-
#if defined(LZ4F_STATIC_LINKING_ONLY)
1223+
#if defined(LZ4F_STATIC_LINKING_ONLY) && \
1224+
NTCTLC_PLUGIN_LZ4_VERSION_NUMBER >= NTCTLC_PLUGIN_LZ4_VERSION_MAKE(1, 9, 4)
12281225

12291226
LZ4F_CustomMem memoryManager;
12301227
bsl::memset(&memoryManager, 0, sizeof memoryManager);
@@ -1495,27 +1492,22 @@ ntsa::Error Zstd::deflateCreate()
14951492
{
14961493
bsl::size_t rc = 0;
14971494

1498-
const int minLevel = ZSTD_minCLevel();
1499-
const int maxLevel = ZSTD_maxCLevel();
1500-
1501-
const int defaultLevel = ZSTD_defaultCLevel();
1502-
15031495
if (d_config.goal().has_value()) {
15041496
switch (d_config.goal().value()) {
15051497
case ntca::CompressionGoal::e_BEST_SIZE:
1506-
d_level = maxLevel;
1498+
d_level = 22;
15071499
break;
15081500
case ntca::CompressionGoal::e_BETTER_SIZE:
1509-
d_level = defaultLevel + bsl::abs((maxLevel - defaultLevel) / 2);
1501+
d_level = 11;
15101502
break;
15111503
case ntca::CompressionGoal::e_BALANCED:
1512-
d_level = defaultLevel;
1504+
d_level = 3;
15131505
break;
15141506
case ntca::CompressionGoal::e_BETTER_SPEED:
1515-
d_level = defaultLevel - bsl::abs((defaultLevel - minLevel) / 2);
1507+
d_level = 2;
15161508
break;
15171509
case ntca::CompressionGoal::e_BEST_SPEED:
1518-
d_level = minLevel;
1510+
d_level = 1;
15191511
break;
15201512
default:
15211513
break;
@@ -2022,10 +2014,14 @@ ntsa::Error Zstd::translateError(bsl::size_t error, const char* operation)
20222014

20232015
if (ZSTD_isError(error)) {
20242016
ZSTD_ErrorCode errorCode = ZSTD_getErrorCode(error);
2025-
if (errorCode == ZSTD_error_dstBuffer_null ||
2026-
errorCode == ZSTD_error_dstSize_tooSmall ||
2017+
if (
2018+
#if NTCTLC_PLUGIN_ZSTD_VERSION_NUMBER >= \
2019+
NTCTLC_PLUGIN_ZSTD_VERSION_MAKE(1, 5, 7)
20272020
errorCode == ZSTD_error_noForwardProgress_destFull ||
2028-
errorCode == ZSTD_error_noForwardProgress_inputEmpty)
2021+
errorCode == ZSTD_error_noForwardProgress_inputEmpty ||
2022+
#endif
2023+
errorCode == ZSTD_error_dstBuffer_null ||
2024+
errorCode == ZSTD_error_dstSize_tooSmall)
20292025
{
20302026
return ntsa::Error(ntsa::Error::e_WOULD_BLOCK);
20312027
}
@@ -2057,7 +2053,7 @@ Zstd::Zstd(const ntca::CompressionConfig& configuration,
20572053
, d_inflaterContext_p(0)
20582054
, d_inflaterBuffer()
20592055
, d_inflaterBufferSize(0)
2060-
, d_level(ZSTD_defaultCLevel())
2056+
, d_level(0)
20612057
, d_dataPool_sp(dataPool)
20622058
, d_config(configuration)
20632059
, d_allocator_p(bslma::Default::allocator(basicAllocator))

0 commit comments

Comments
 (0)