diff --git a/src/ZstdSharp/Unsafe/ZSTD_blockCompressor.cs b/src/ZstdSharp/Unsafe/ZSTD_blockCompressor.cs new file mode 100644 index 0000000..28f5534 --- /dev/null +++ b/src/ZstdSharp/Unsafe/ZSTD_blockCompressor.cs @@ -0,0 +1,7 @@ +using System.Runtime.InteropServices; + +namespace ZstdSharp.Unsafe +{ + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + public unsafe delegate nuint ZSTD_blockCompressor(ZSTD_matchState_t* bs, seqStore_t* seqStore, uint* rep, void* src, nuint srcSize); +} \ No newline at end of file diff --git a/src/ZstdSharp/Unsafe/ZSTD_getAllMatchesFn.cs b/src/ZstdSharp/Unsafe/ZSTD_getAllMatchesFn.cs new file mode 100644 index 0000000..20cbfe5 --- /dev/null +++ b/src/ZstdSharp/Unsafe/ZSTD_getAllMatchesFn.cs @@ -0,0 +1,7 @@ +using System.Runtime.InteropServices; + +namespace ZstdSharp.Unsafe +{ + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + public unsafe delegate uint ZSTD_getAllMatchesFn(ZSTD_match_t* param0, ZSTD_matchState_t* param1, uint* param2, byte* param3, byte* param4, uint* rep, uint ll0, uint lengthToBeat); +} \ No newline at end of file diff --git a/src/ZstdSharp/Unsafe/ZstdCompress.cs b/src/ZstdSharp/Unsafe/ZstdCompress.cs index 4649685..97ea36d 100644 --- a/src/ZstdSharp/Unsafe/ZstdCompress.cs +++ b/src/ZstdSharp/Unsafe/ZstdCompress.cs @@ -2722,14 +2722,14 @@ private static nuint ZSTD_entropyCompressSeqStore(seqStore_t* seqStorePtr, ZSTD_ return cSize; } - public static delegate* managed[][] blockCompressor = new delegate* managed[4][] { new delegate* managed[10] { &ZSTD_compressBlock_fast, &ZSTD_compressBlock_fast, &ZSTD_compressBlock_doubleFast, &ZSTD_compressBlock_greedy, &ZSTD_compressBlock_lazy, &ZSTD_compressBlock_lazy2, &ZSTD_compressBlock_btlazy2, &ZSTD_compressBlock_btopt, &ZSTD_compressBlock_btultra, &ZSTD_compressBlock_btultra2 }, new delegate* managed[10] { &ZSTD_compressBlock_fast_extDict, &ZSTD_compressBlock_fast_extDict, &ZSTD_compressBlock_doubleFast_extDict, &ZSTD_compressBlock_greedy_extDict, &ZSTD_compressBlock_lazy_extDict, &ZSTD_compressBlock_lazy2_extDict, &ZSTD_compressBlock_btlazy2_extDict, &ZSTD_compressBlock_btopt_extDict, &ZSTD_compressBlock_btultra_extDict, &ZSTD_compressBlock_btultra_extDict }, new delegate* managed[10] { &ZSTD_compressBlock_fast_dictMatchState, &ZSTD_compressBlock_fast_dictMatchState, &ZSTD_compressBlock_doubleFast_dictMatchState, &ZSTD_compressBlock_greedy_dictMatchState, &ZSTD_compressBlock_lazy_dictMatchState, &ZSTD_compressBlock_lazy2_dictMatchState, &ZSTD_compressBlock_btlazy2_dictMatchState, &ZSTD_compressBlock_btopt_dictMatchState, &ZSTD_compressBlock_btultra_dictMatchState, &ZSTD_compressBlock_btultra_dictMatchState }, new delegate* managed[10] { null, null, null, &ZSTD_compressBlock_greedy_dedicatedDictSearch, &ZSTD_compressBlock_lazy_dedicatedDictSearch, &ZSTD_compressBlock_lazy2_dedicatedDictSearch, null, null, null, null } }; - public static delegate* managed[][] rowBasedBlockCompressors = new delegate* managed[4][] { new delegate* managed[3] { &ZSTD_compressBlock_greedy_row, &ZSTD_compressBlock_lazy_row, &ZSTD_compressBlock_lazy2_row }, new delegate* managed[3] { &ZSTD_compressBlock_greedy_extDict_row, &ZSTD_compressBlock_lazy_extDict_row, &ZSTD_compressBlock_lazy2_extDict_row }, new delegate* managed[3] { &ZSTD_compressBlock_greedy_dictMatchState_row, &ZSTD_compressBlock_lazy_dictMatchState_row, &ZSTD_compressBlock_lazy2_dictMatchState_row }, new delegate* managed[3] { &ZSTD_compressBlock_greedy_dedicatedDictSearch_row, &ZSTD_compressBlock_lazy_dedicatedDictSearch_row, &ZSTD_compressBlock_lazy2_dedicatedDictSearch_row } }; + public static ZSTD_blockCompressor[][] blockCompressor = new ZSTD_blockCompressor[4][] { new ZSTD_blockCompressor[10] { ZSTD_compressBlock_fast, ZSTD_compressBlock_fast, ZSTD_compressBlock_doubleFast, ZSTD_compressBlock_greedy, ZSTD_compressBlock_lazy, ZSTD_compressBlock_lazy2, ZSTD_compressBlock_btlazy2, ZSTD_compressBlock_btopt, ZSTD_compressBlock_btultra, ZSTD_compressBlock_btultra2 }, new ZSTD_blockCompressor[10] { ZSTD_compressBlock_fast_extDict, ZSTD_compressBlock_fast_extDict, ZSTD_compressBlock_doubleFast_extDict, ZSTD_compressBlock_greedy_extDict, ZSTD_compressBlock_lazy_extDict, ZSTD_compressBlock_lazy2_extDict, ZSTD_compressBlock_btlazy2_extDict, ZSTD_compressBlock_btopt_extDict, ZSTD_compressBlock_btultra_extDict, ZSTD_compressBlock_btultra_extDict }, new ZSTD_blockCompressor[10] { ZSTD_compressBlock_fast_dictMatchState, ZSTD_compressBlock_fast_dictMatchState, ZSTD_compressBlock_doubleFast_dictMatchState, ZSTD_compressBlock_greedy_dictMatchState, ZSTD_compressBlock_lazy_dictMatchState, ZSTD_compressBlock_lazy2_dictMatchState, ZSTD_compressBlock_btlazy2_dictMatchState, ZSTD_compressBlock_btopt_dictMatchState, ZSTD_compressBlock_btultra_dictMatchState, ZSTD_compressBlock_btultra_dictMatchState }, new ZSTD_blockCompressor[10] { null, null, null, ZSTD_compressBlock_greedy_dedicatedDictSearch, ZSTD_compressBlock_lazy_dedicatedDictSearch, ZSTD_compressBlock_lazy2_dedicatedDictSearch, null, null, null, null } }; + public static ZSTD_blockCompressor[][] rowBasedBlockCompressors = new ZSTD_blockCompressor[4][] { new ZSTD_blockCompressor[3] { ZSTD_compressBlock_greedy_row, ZSTD_compressBlock_lazy_row, ZSTD_compressBlock_lazy2_row }, new ZSTD_blockCompressor[3] { ZSTD_compressBlock_greedy_extDict_row, ZSTD_compressBlock_lazy_extDict_row, ZSTD_compressBlock_lazy2_extDict_row }, new ZSTD_blockCompressor[3] { ZSTD_compressBlock_greedy_dictMatchState_row, ZSTD_compressBlock_lazy_dictMatchState_row, ZSTD_compressBlock_lazy2_dictMatchState_row }, new ZSTD_blockCompressor[3] { ZSTD_compressBlock_greedy_dedicatedDictSearch_row, ZSTD_compressBlock_lazy_dedicatedDictSearch_row, ZSTD_compressBlock_lazy2_dedicatedDictSearch_row } }; /* ZSTD_selectBlockCompressor() : * Not static, but internal use only (used by long distance matcher) * assumption : strat is a valid strategy */ - public static delegate* managed ZSTD_selectBlockCompressor(ZSTD_strategy strat, ZSTD_paramSwitch_e useRowMatchFinder, ZSTD_dictMode_e dictMode) + public static ZSTD_blockCompressor ZSTD_selectBlockCompressor(ZSTD_strategy strat, ZSTD_paramSwitch_e useRowMatchFinder, ZSTD_dictMode_e dictMode) { - delegate* managed selectedCompressor; + ZSTD_blockCompressor selectedCompressor; assert(ZSTD_cParam_withinBounds(ZSTD_cParameter.ZSTD_c_strategy, (int)strat) != 0); if (ZSTD_rowMatchFinderUsed(strat, useRowMatchFinder) != 0) { @@ -2824,7 +2824,7 @@ private static nuint ZSTD_buildSeqStore(ZSTD_CCtx_s* zc, void* src, nuint srcSiz } else { - delegate* managed blockCompressor = ZSTD_selectBlockCompressor(zc->appliedParams.cParams.strategy, zc->appliedParams.useRowMatchFinder, dictMode); + ZSTD_blockCompressor blockCompressor = ZSTD_selectBlockCompressor(zc->appliedParams.cParams.strategy, zc->appliedParams.useRowMatchFinder, dictMode); ms->ldmSeqStore = null; lastLLSize = blockCompressor(ms, &zc->seqStore, zc->blockState.nextCBlock->rep, src, srcSize); } diff --git a/src/ZstdSharp/Unsafe/ZstdLdm.cs b/src/ZstdSharp/Unsafe/ZstdLdm.cs index 70b17c5..c1f31db 100644 --- a/src/ZstdSharp/Unsafe/ZstdLdm.cs +++ b/src/ZstdSharp/Unsafe/ZstdLdm.cs @@ -684,7 +684,7 @@ public static nuint ZSTD_ldm_blockCompress(rawSeqStore_t* rawSeqStore, ZSTD_matc { ZSTD_compressionParameters* cParams = &ms->cParams; uint minMatch = cParams->minMatch; - delegate* managed blockCompressor = ZSTD_selectBlockCompressor(cParams->strategy, useRowMatchFinder, ZSTD_matchState_dictMode(ms)); + ZSTD_blockCompressor blockCompressor = ZSTD_selectBlockCompressor(cParams->strategy, useRowMatchFinder, ZSTD_matchState_dictMode(ms)); /* Input bounds */ byte* istart = (byte*)src; byte* iend = istart + srcSize; diff --git a/src/ZstdSharp/Unsafe/ZstdOpt.cs b/src/ZstdSharp/Unsafe/ZstdOpt.cs index 561deba..9523313 100644 --- a/src/ZstdSharp/Unsafe/ZstdOpt.cs +++ b/src/ZstdSharp/Unsafe/ZstdOpt.cs @@ -799,8 +799,8 @@ private static uint ZSTD_btGetAllMatches_dictMatchState_6(ZSTD_match_t* matches, return ZSTD_btGetAllMatches_internal(matches, ms, nextToUpdate3, ip, iHighLimit, rep, ll0, lengthToBeat, ZSTD_dictMode_e.ZSTD_dictMatchState, 6); } - public static delegate* managed[][] getAllMatchesFns = new delegate* managed[3][] { new delegate* managed[4] { &ZSTD_btGetAllMatches_noDict_3, &ZSTD_btGetAllMatches_noDict_4, &ZSTD_btGetAllMatches_noDict_5, &ZSTD_btGetAllMatches_noDict_6 }, new delegate* managed[4] { &ZSTD_btGetAllMatches_extDict_3, &ZSTD_btGetAllMatches_extDict_4, &ZSTD_btGetAllMatches_extDict_5, &ZSTD_btGetAllMatches_extDict_6 }, new delegate* managed[4] { &ZSTD_btGetAllMatches_dictMatchState_3, &ZSTD_btGetAllMatches_dictMatchState_4, &ZSTD_btGetAllMatches_dictMatchState_5, &ZSTD_btGetAllMatches_dictMatchState_6 } }; - private static delegate* managed ZSTD_selectBtGetAllMatches(ZSTD_matchState_t* ms, ZSTD_dictMode_e dictMode) + public static ZSTD_getAllMatchesFn[][] getAllMatchesFns = new ZSTD_getAllMatchesFn[3][] { new ZSTD_getAllMatchesFn[4] { ZSTD_btGetAllMatches_noDict_3, ZSTD_btGetAllMatches_noDict_4, ZSTD_btGetAllMatches_noDict_5, ZSTD_btGetAllMatches_noDict_6 }, new ZSTD_getAllMatchesFn[4] { ZSTD_btGetAllMatches_extDict_3, ZSTD_btGetAllMatches_extDict_4, ZSTD_btGetAllMatches_extDict_5, ZSTD_btGetAllMatches_extDict_6 }, new ZSTD_getAllMatchesFn[4] { ZSTD_btGetAllMatches_dictMatchState_3, ZSTD_btGetAllMatches_dictMatchState_4, ZSTD_btGetAllMatches_dictMatchState_5, ZSTD_btGetAllMatches_dictMatchState_6 } }; + private static ZSTD_getAllMatchesFn ZSTD_selectBtGetAllMatches(ZSTD_matchState_t* ms, ZSTD_dictMode_e dictMode) { uint mls = 3 > (ms->cParams.minMatch < 6 ? ms->cParams.minMatch : 6) ? 3 : ms->cParams.minMatch < 6 ? ms->cParams.minMatch : 6; assert((uint)dictMode < 3); @@ -953,7 +953,7 @@ private static nuint ZSTD_compressBlock_opt_generic(ZSTD_matchState_t* ms, seqSt byte* @base = ms->window.@base; byte* prefixStart = @base + ms->window.dictLimit; ZSTD_compressionParameters* cParams = &ms->cParams; - delegate* managed getAllMatches = ZSTD_selectBtGetAllMatches(ms, dictMode); + ZSTD_getAllMatchesFn getAllMatches = ZSTD_selectBtGetAllMatches(ms, dictMode); uint sufficient_len = cParams->targetLength < (1 << 12) - 1 ? cParams->targetLength : (1 << 12) - 1; uint minMatch = (uint)(cParams->minMatch == 3 ? 3 : 4); uint nextToUpdate3 = ms->nextToUpdate; diff --git a/src/ZstdSharp/ZstdSharp.csproj b/src/ZstdSharp/ZstdSharp.csproj index 6747b49..69edf42 100644 --- a/src/ZstdSharp/ZstdSharp.csproj +++ b/src/ZstdSharp/ZstdSharp.csproj @@ -17,7 +17,7 @@ true true snupkg - 0.6.6 + 0.6.7