Skip to content

Commit cba7896

Browse files
committed
Comments
1 parent 2b219c9 commit cba7896

9 files changed

+208
-0
lines changed

src/ZstdSharp/Unsafe/FseDecompress.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ private static nuint FSE_decompress_usingDTable_generic(void* dst, nuint maxDstS
144144
FSE_DState_t state1;
145145
FSE_DState_t state2;
146146
{
147+
/* Init */
147148
nuint _var_err__ = BIT_initDStream(&bitD, cSrc, cSrcSize);
148149
if (ERR_isError(_var_err__))
149150
return _var_err__;

src/ZstdSharp/Unsafe/HufCompress.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ private static nuint HUF_compressWeights(void* dst, nuint dstSize, void* weightT
5050

5151
tableLog = FSE_optimalTableLog(tableLog, wtSize, maxSymbolValue);
5252
{
53+
/* useLowProbCount */
5354
nuint _var_err__ = FSE_normalizeCount(wksp->norm, tableLog, wksp->count, wtSize, maxSymbolValue, 0);
5455
if (ERR_isError(_var_err__))
5556
return _var_err__;
@@ -63,6 +64,7 @@ private static nuint HUF_compressWeights(void* dst, nuint dstSize, void* weightT
6364
}
6465

6566
{
67+
/* Compress */
6668
nuint _var_err__ = FSE_buildCTable_wksp(wksp->CTable, wksp->norm, maxSymbolValue, tableLog, wksp->scratchBuffer, sizeof(uint) * 41);
6769
if (ERR_isError(_var_err__))
6870
return _var_err__;
@@ -197,6 +199,7 @@ private static nuint HUF_readCTable(nuint* CTable, uint* maxSymbolValuePtr, void
197199
uint tableLog = 0;
198200
uint nbSymbols = 0;
199201
nuint* ct = CTable + 1;
202+
/* get symbol weights */
200203
nuint readSize = HUF_readStats(huffWeight, 255 + 1, rankVal, &nbSymbols, &tableLog, src, srcSize);
201204
if (ERR_isError(readSize))
202205
return readSize;

src/ZstdSharp/Unsafe/HufDecompress.cs

Lines changed: 127 additions & 0 deletions
Large diffs are not rendered by default.

src/ZstdSharp/Unsafe/ZstdCompress.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1270,6 +1270,7 @@ public static nuint ZSTD_CCtx_setParametersUsingCCtxParams(ZSTD_CCtx_s* cctx, ZS
12701270
public static nuint ZSTD_CCtx_setCParams(ZSTD_CCtx_s* cctx, ZSTD_compressionParameters cparams)
12711271
{
12721272
{
1273+
/* only update if all parameters are valid */
12731274
nuint err_code = ZSTD_checkCParams(cparams);
12741275
if (ERR_isError(err_code))
12751276
{
@@ -1376,6 +1377,7 @@ public static nuint ZSTD_CCtx_setFParams(ZSTD_CCtx_s* cctx, ZSTD_frameParameters
13761377
public static nuint ZSTD_CCtx_setParams(ZSTD_CCtx_s* cctx, ZSTD_parameters @params)
13771378
{
13781379
{
1380+
/* First check cParams, because we want to update all or none. */
13791381
nuint err_code = ZSTD_checkCParams(@params.cParams);
13801382
if (ERR_isError(err_code))
13811383
{
@@ -1384,6 +1386,7 @@ public static nuint ZSTD_CCtx_setParams(ZSTD_CCtx_s* cctx, ZSTD_parameters @para
13841386
}
13851387

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

13941397
{
1398+
/* Finally set cParams, which should succeed. */
13951399
nuint err_code = ZSTD_CCtx_setCParams(cctx, @params.cParams);
13961400
if (ERR_isError(err_code))
13971401
{
@@ -3347,6 +3351,7 @@ private static nuint ZSTD_buildSeqStore(ZSTD_CCtx_s* zc, void* src, nuint srcSiz
33473351
ldmSeqStore.seq = zc->ldmSequences;
33483352
ldmSeqStore.capacity = zc->maxNbLdmSequences;
33493353
{
3354+
/* Updates ldmSeqStore.size */
33503355
nuint err_code = ZSTD_ldm_generateSequences(&zc->ldmState, &ldmSeqStore, &zc->appliedParams.ldmParams, src, srcSize);
33513356
if (ERR_isError(err_code))
33523357
{
@@ -5343,6 +5348,7 @@ private static nuint ZSTD_compressBegin_internal(ZSTD_CCtx_s* cctx, void* dict,
53435348
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)
53445349
{
53455350
{
5351+
/* compression parameters verification and optimization */
53465352
nuint err_code = ZSTD_checkCParams(@params->cParams);
53475353
if (ERR_isError(err_code))
53485354
{
@@ -5908,6 +5914,7 @@ public static nuint ZSTD_compressBegin_usingCDict(ZSTD_CCtx_s* cctx, ZSTD_CDict_
59085914
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)
59095915
{
59105916
{
5917+
/* will check if cdict != NULL */
59115918
nuint err_code = ZSTD_compressBegin_usingCDict_internal(cctx, cdict, fParams, srcSize);
59125919
if (ERR_isError(err_code))
59135920
{
@@ -6048,6 +6055,7 @@ private static nuint ZSTD_initCStream_internal(ZSTD_CCtx_s* zcs, void* dict, nui
60486055
}
60496056
else
60506057
{
6058+
/* Dictionary is cleared if !cdict */
60516059
nuint err_code = ZSTD_CCtx_refCDict(zcs, cdict);
60526060
if (ERR_isError(err_code))
60536061
{
@@ -6617,6 +6625,7 @@ private static nuint ZSTD_CCtx_init_compressStream2(ZSTD_CCtx_s* cctx, ZSTD_EndD
66176625
ZSTD_CCtx_params_s @params = cctx->requestedParams;
66186626
ZSTD_prefixDict_s prefixDict = cctx->prefixDict;
66196627
{
6628+
/* Init the local dict if present. */
66206629
nuint err_code = ZSTD_initLocalDict(cctx);
66216630
if (ERR_isError(err_code))
66226631
{
@@ -6771,6 +6780,7 @@ public static nuint ZSTD_compressStream2(ZSTD_CCtx_s* cctx, ZSTD_outBuffer_s* ou
67716780
}
67726781

67736782
{
6783+
/* end of transparent initialization stage */
67746784
nuint err_code = ZSTD_checkBufferStability(cctx, output, input, endOp);
67756785
if (ERR_isError(err_code))
67766786
{

src/ZstdSharp/Unsafe/ZstdCompressSequences.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -486,6 +486,7 @@ private static nuint ZSTD_buildCTable(void* dst, nuint dstCapacity, uint* nextCT
486486
return 0;
487487
case symbolEncodingType_e.set_basic:
488488
{
489+
/* note : could be pre-calculated */
489490
nuint err_code = FSE_buildCTable_wksp(nextCTable, defaultNorm, defaultMax, defaultNormLog, entropyWorkspace, entropyWorkspaceSize);
490491
if (ERR_isError(err_code))
491492
{

src/ZstdSharp/Unsafe/ZstdDdict.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ private static nuint ZSTD_initDDict_internal(ZSTD_DDict_s* ddict, void* dict, nu
109109
ddict->dictSize = dictSize;
110110
ddict->entropy.hufTable[0] = 12 * 0x1000001;
111111
{
112+
/* parse dictionary content */
112113
nuint err_code = ZSTD_loadEntropy_intoDDict(ddict, dictContentType);
113114
if (ERR_isError(err_code))
114115
{

src/ZstdSharp/Unsafe/ZstdDecompress.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1125,6 +1125,7 @@ private static nuint ZSTD_decompressMultiFrame(ZSTD_DCtx_s* dctx, void* dst, nui
11251125

11261126
if (ddict != null)
11271127
{
1128+
/* we were called from ZSTD_decompress_usingDDict */
11281129
nuint err_code = ZSTD_decompressBegin_usingDDict(dctx, ddict);
11291130
if (ERR_isError(err_code))
11301131
{
@@ -1133,6 +1134,8 @@ private static nuint ZSTD_decompressMultiFrame(ZSTD_DCtx_s* dctx, void* dst, nui
11331134
}
11341135
else
11351136
{
1137+
/* this will initialize correctly with no dict if dict == NULL, so
1138+
* use this in all cases but ddict */
11361139
nuint err_code = ZSTD_decompressBegin_usingDict(dctx, dict, dictSize);
11371140
if (ERR_isError(err_code))
11381141
{
@@ -2556,6 +2559,7 @@ public static nuint ZSTD_decompressStream(ZSTD_DCtx_s* zds, ZSTD_outBuffer_s* ou
25562559

25572560
input->pos = input->size;
25582561
{
2562+
/* check first few bytes */
25592563
nuint err_code = ZSTD_getFrameHeader_advanced(&zds->fParams, zds->headerBuffer, zds->lhSize, zds->format);
25602564
if (ERR_isError(err_code))
25612565
{

0 commit comments

Comments
 (0)