Skip to content

Commit

Permalink
Comments
Browse files Browse the repository at this point in the history
  • Loading branch information
oleg-st committed May 17, 2024
1 parent 2b219c9 commit cba7896
Show file tree
Hide file tree
Showing 9 changed files with 208 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/ZstdSharp/Unsafe/FseDecompress.cs
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ private static nuint FSE_decompress_usingDTable_generic(void* dst, nuint maxDstS
FSE_DState_t state1;
FSE_DState_t state2;
{
/* Init */
nuint _var_err__ = BIT_initDStream(&bitD, cSrc, cSrcSize);
if (ERR_isError(_var_err__))
return _var_err__;
Expand Down
3 changes: 3 additions & 0 deletions src/ZstdSharp/Unsafe/HufCompress.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ private static nuint HUF_compressWeights(void* dst, nuint dstSize, void* weightT

tableLog = FSE_optimalTableLog(tableLog, wtSize, maxSymbolValue);
{
/* useLowProbCount */
nuint _var_err__ = FSE_normalizeCount(wksp->norm, tableLog, wksp->count, wtSize, maxSymbolValue, 0);
if (ERR_isError(_var_err__))
return _var_err__;
Expand All @@ -63,6 +64,7 @@ private static nuint HUF_compressWeights(void* dst, nuint dstSize, void* weightT
}

{
/* Compress */
nuint _var_err__ = FSE_buildCTable_wksp(wksp->CTable, wksp->norm, maxSymbolValue, tableLog, wksp->scratchBuffer, sizeof(uint) * 41);
if (ERR_isError(_var_err__))
return _var_err__;
Expand Down Expand Up @@ -197,6 +199,7 @@ private static nuint HUF_readCTable(nuint* CTable, uint* maxSymbolValuePtr, void
uint tableLog = 0;
uint nbSymbols = 0;
nuint* ct = CTable + 1;
/* get symbol weights */
nuint readSize = HUF_readStats(huffWeight, 255 + 1, rankVal, &nbSymbols, &tableLog, src, srcSize);
if (ERR_isError(readSize))
return readSize;
Expand Down
127 changes: 127 additions & 0 deletions src/ZstdSharp/Unsafe/HufDecompress.cs

Large diffs are not rendered by default.

10 changes: 10 additions & 0 deletions src/ZstdSharp/Unsafe/ZstdCompress.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1270,6 +1270,7 @@ public static nuint ZSTD_CCtx_setParametersUsingCCtxParams(ZSTD_CCtx_s* cctx, ZS
public static nuint ZSTD_CCtx_setCParams(ZSTD_CCtx_s* cctx, ZSTD_compressionParameters cparams)
{
{
/* only update if all parameters are valid */
nuint err_code = ZSTD_checkCParams(cparams);
if (ERR_isError(err_code))
{
Expand Down Expand Up @@ -1376,6 +1377,7 @@ public static nuint ZSTD_CCtx_setFParams(ZSTD_CCtx_s* cctx, ZSTD_frameParameters
public static nuint ZSTD_CCtx_setParams(ZSTD_CCtx_s* cctx, ZSTD_parameters @params)
{
{
/* First check cParams, because we want to update all or none. */
nuint err_code = ZSTD_checkCParams(@params.cParams);
if (ERR_isError(err_code))
{
Expand All @@ -1384,6 +1386,7 @@ public static nuint ZSTD_CCtx_setParams(ZSTD_CCtx_s* cctx, ZSTD_parameters @para
}

{
/* Next set fParams, because this could fail if the cctx isn't in init stage. */
nuint err_code = ZSTD_CCtx_setFParams(cctx, @params.fParams);
if (ERR_isError(err_code))
{
Expand All @@ -1392,6 +1395,7 @@ public static nuint ZSTD_CCtx_setParams(ZSTD_CCtx_s* cctx, ZSTD_parameters @para
}

{
/* Finally set cParams, which should succeed. */
nuint err_code = ZSTD_CCtx_setCParams(cctx, @params.cParams);
if (ERR_isError(err_code))
{
Expand Down Expand Up @@ -3347,6 +3351,7 @@ private static nuint ZSTD_buildSeqStore(ZSTD_CCtx_s* zc, void* src, nuint srcSiz
ldmSeqStore.seq = zc->ldmSequences;
ldmSeqStore.capacity = zc->maxNbLdmSequences;
{
/* Updates ldmSeqStore.size */
nuint err_code = ZSTD_ldm_generateSequences(&zc->ldmState, &ldmSeqStore, &zc->appliedParams.ldmParams, src, srcSize);
if (ERR_isError(err_code))
{
Expand Down Expand Up @@ -5343,6 +5348,7 @@ private static nuint ZSTD_compressBegin_internal(ZSTD_CCtx_s* cctx, void* dict,
private static nuint ZSTD_compressBegin_advanced_internal(ZSTD_CCtx_s* cctx, void* dict, nuint dictSize, ZSTD_dictContentType_e dictContentType, ZSTD_dictTableLoadMethod_e dtlm, ZSTD_CDict_s* cdict, ZSTD_CCtx_params_s* @params, ulong pledgedSrcSize)
{
{
/* compression parameters verification and optimization */
nuint err_code = ZSTD_checkCParams(@params->cParams);
if (ERR_isError(err_code))
{
Expand Down Expand Up @@ -5908,6 +5914,7 @@ public static nuint ZSTD_compressBegin_usingCDict(ZSTD_CCtx_s* cctx, ZSTD_CDict_
private static nuint ZSTD_compress_usingCDict_internal(ZSTD_CCtx_s* cctx, void* dst, nuint dstCapacity, void* src, nuint srcSize, ZSTD_CDict_s* cdict, ZSTD_frameParameters fParams)
{
{
/* will check if cdict != NULL */
nuint err_code = ZSTD_compressBegin_usingCDict_internal(cctx, cdict, fParams, srcSize);
if (ERR_isError(err_code))
{
Expand Down Expand Up @@ -6048,6 +6055,7 @@ private static nuint ZSTD_initCStream_internal(ZSTD_CCtx_s* zcs, void* dict, nui
}
else
{
/* Dictionary is cleared if !cdict */
nuint err_code = ZSTD_CCtx_refCDict(zcs, cdict);
if (ERR_isError(err_code))
{
Expand Down Expand Up @@ -6617,6 +6625,7 @@ private static nuint ZSTD_CCtx_init_compressStream2(ZSTD_CCtx_s* cctx, ZSTD_EndD
ZSTD_CCtx_params_s @params = cctx->requestedParams;
ZSTD_prefixDict_s prefixDict = cctx->prefixDict;
{
/* Init the local dict if present. */
nuint err_code = ZSTD_initLocalDict(cctx);
if (ERR_isError(err_code))
{
Expand Down Expand Up @@ -6771,6 +6780,7 @@ public static nuint ZSTD_compressStream2(ZSTD_CCtx_s* cctx, ZSTD_outBuffer_s* ou
}

{
/* end of transparent initialization stage */
nuint err_code = ZSTD_checkBufferStability(cctx, output, input, endOp);
if (ERR_isError(err_code))
{
Expand Down
1 change: 1 addition & 0 deletions src/ZstdSharp/Unsafe/ZstdCompressSequences.cs
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,7 @@ private static nuint ZSTD_buildCTable(void* dst, nuint dstCapacity, uint* nextCT
return 0;
case symbolEncodingType_e.set_basic:
{
/* note : could be pre-calculated */
nuint err_code = FSE_buildCTable_wksp(nextCTable, defaultNorm, defaultMax, defaultNormLog, entropyWorkspace, entropyWorkspaceSize);
if (ERR_isError(err_code))
{
Expand Down
1 change: 1 addition & 0 deletions src/ZstdSharp/Unsafe/ZstdDdict.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ private static nuint ZSTD_initDDict_internal(ZSTD_DDict_s* ddict, void* dict, nu
ddict->dictSize = dictSize;
ddict->entropy.hufTable[0] = 12 * 0x1000001;
{
/* parse dictionary content */
nuint err_code = ZSTD_loadEntropy_intoDDict(ddict, dictContentType);
if (ERR_isError(err_code))
{
Expand Down
4 changes: 4 additions & 0 deletions src/ZstdSharp/Unsafe/ZstdDecompress.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1125,6 +1125,7 @@ private static nuint ZSTD_decompressMultiFrame(ZSTD_DCtx_s* dctx, void* dst, nui

if (ddict != null)
{
/* we were called from ZSTD_decompress_usingDDict */
nuint err_code = ZSTD_decompressBegin_usingDDict(dctx, ddict);
if (ERR_isError(err_code))
{
Expand All @@ -1133,6 +1134,8 @@ private static nuint ZSTD_decompressMultiFrame(ZSTD_DCtx_s* dctx, void* dst, nui
}
else
{
/* this will initialize correctly with no dict if dict == NULL, so
* use this in all cases but ddict */
nuint err_code = ZSTD_decompressBegin_usingDict(dctx, dict, dictSize);
if (ERR_isError(err_code))
{
Expand Down Expand Up @@ -2556,6 +2559,7 @@ public static nuint ZSTD_decompressStream(ZSTD_DCtx_s* zds, ZSTD_outBuffer_s* ou

input->pos = input->size;
{
/* check first few bytes */
nuint err_code = ZSTD_getFrameHeader_advanced(&zds->fParams, zds->headerBuffer, zds->lhSize, zds->format);
if (ERR_isError(err_code))
{
Expand Down
Loading

0 comments on commit cba7896

Please sign in to comment.