First working pass at refactor of loadZstdDictionary()
This commit is contained in:
@@ -2768,37 +2768,12 @@ static size_t ZSTD_checkDictNCount(short* normalizedCounter, unsigned dictMaxSym
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
size_t ZSTD_loadCEntropy(ZSTD_compressedBlockState_t* bs, void* workspace,
|
||||||
/* Dictionary format :
|
short* offcodeNCount, unsigned* offcodeMaxValue,
|
||||||
* See :
|
const void* const dict, size_t dictSize)
|
||||||
* https://github.com/facebook/zstd/blob/master/doc/zstd_compression_format.md#dictionary-format
|
|
||||||
*/
|
|
||||||
/*! ZSTD_loadZstdDictionary() :
|
|
||||||
* @return : dictID, or an error code
|
|
||||||
* assumptions : magic number supposed already checked
|
|
||||||
* dictSize supposed >= 8
|
|
||||||
*/
|
|
||||||
static size_t ZSTD_loadZstdDictionary(ZSTD_compressedBlockState_t* bs,
|
|
||||||
ZSTD_matchState_t* ms,
|
|
||||||
ZSTD_cwksp* ws,
|
|
||||||
ZSTD_CCtx_params const* params,
|
|
||||||
const void* dict, size_t dictSize,
|
|
||||||
ZSTD_dictTableLoadMethod_e dtlm,
|
|
||||||
void* workspace)
|
|
||||||
{
|
{
|
||||||
const BYTE* dictPtr = (const BYTE*)dict;
|
const BYTE* dictPtr = (const BYTE*)dict;
|
||||||
const BYTE* const dictEnd = dictPtr + dictSize;
|
const BYTE* const dictEnd = dictPtr + dictSize - 8;
|
||||||
short offcodeNCount[MaxOff+1];
|
|
||||||
unsigned offcodeMaxValue = MaxOff;
|
|
||||||
size_t dictID;
|
|
||||||
|
|
||||||
ZSTD_STATIC_ASSERT(HUF_WORKSPACE_SIZE >= (1<<MAX(MLFSELog,LLFSELog)));
|
|
||||||
assert(dictSize >= 8);
|
|
||||||
assert(MEM_readLE32(dictPtr) == ZSTD_MAGIC_DICTIONARY);
|
|
||||||
|
|
||||||
dictPtr += 4; /* skip magic number */
|
|
||||||
dictID = params->fParams.noDictIDFlag ? 0 : MEM_readLE32(dictPtr);
|
|
||||||
dictPtr += 4;
|
|
||||||
|
|
||||||
{ unsigned maxSymbolValue = 255;
|
{ unsigned maxSymbolValue = 255;
|
||||||
size_t const hufHeaderSize = HUF_readCTable((HUF_CElt*)bs->entropy.huf.CTable, &maxSymbolValue, dictPtr, dictEnd-dictPtr);
|
size_t const hufHeaderSize = HUF_readCTable((HUF_CElt*)bs->entropy.huf.CTable, &maxSymbolValue, dictPtr, dictEnd-dictPtr);
|
||||||
@@ -2808,7 +2783,7 @@ static size_t ZSTD_loadZstdDictionary(ZSTD_compressedBlockState_t* bs,
|
|||||||
}
|
}
|
||||||
|
|
||||||
{ unsigned offcodeLog;
|
{ unsigned offcodeLog;
|
||||||
size_t const offcodeHeaderSize = FSE_readNCount(offcodeNCount, &offcodeMaxValue, &offcodeLog, dictPtr, dictEnd-dictPtr);
|
size_t const offcodeHeaderSize = FSE_readNCount(offcodeNCount, offcodeMaxValue, &offcodeLog, dictPtr, dictEnd-dictPtr);
|
||||||
RETURN_ERROR_IF(FSE_isError(offcodeHeaderSize), dictionary_corrupted);
|
RETURN_ERROR_IF(FSE_isError(offcodeHeaderSize), dictionary_corrupted);
|
||||||
RETURN_ERROR_IF(offcodeLog > OffFSELog, dictionary_corrupted);
|
RETURN_ERROR_IF(offcodeLog > OffFSELog, dictionary_corrupted);
|
||||||
/* Defer checking offcodeMaxValue because we need to know the size of the dictionary content */
|
/* Defer checking offcodeMaxValue because we need to know the size of the dictionary content */
|
||||||
@@ -2856,6 +2831,43 @@ static size_t ZSTD_loadZstdDictionary(ZSTD_compressedBlockState_t* bs,
|
|||||||
bs->rep[1] = MEM_readLE32(dictPtr+4);
|
bs->rep[1] = MEM_readLE32(dictPtr+4);
|
||||||
bs->rep[2] = MEM_readLE32(dictPtr+8);
|
bs->rep[2] = MEM_readLE32(dictPtr+8);
|
||||||
dictPtr += 12;
|
dictPtr += 12;
|
||||||
|
DEBUGLOG(1, "size %u)", (unsigned)(dictPtr - (const BYTE*)dict));
|
||||||
|
return dictPtr - (const BYTE*)dict;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Dictionary format :
|
||||||
|
* See :
|
||||||
|
* https://github.com/facebook/zstd/blob/master/doc/zstd_compression_format.md#dictionary-format
|
||||||
|
*/
|
||||||
|
/*! ZSTD_loadZstdDictionary() :
|
||||||
|
* @return : dictID, or an error code
|
||||||
|
* assumptions : magic number supposed already checked
|
||||||
|
* dictSize supposed > 8
|
||||||
|
*/
|
||||||
|
static size_t ZSTD_loadZstdDictionary(ZSTD_compressedBlockState_t* bs,
|
||||||
|
ZSTD_matchState_t* ms,
|
||||||
|
ZSTD_cwksp* ws,
|
||||||
|
ZSTD_CCtx_params const* params,
|
||||||
|
const void* dict, size_t dictSize,
|
||||||
|
ZSTD_dictTableLoadMethod_e dtlm,
|
||||||
|
void* workspace)
|
||||||
|
{
|
||||||
|
size_t dictID;
|
||||||
|
size_t eSize;
|
||||||
|
const BYTE* dictPtr = (const BYTE*)dict;
|
||||||
|
const BYTE* const dictEnd = dictPtr + dictSize;
|
||||||
|
short offcodeNCount[MaxOff+1];
|
||||||
|
unsigned offcodeMaxValue = MaxOff;
|
||||||
|
ZSTD_STATIC_ASSERT(HUF_WORKSPACE_SIZE >= (1<<MAX(MLFSELog,LLFSELog)));
|
||||||
|
assert(dictSize > 8);
|
||||||
|
assert(MEM_readLE32(dictPtr) == ZSTD_MAGIC_DICTIONARY);
|
||||||
|
eSize = ZSTD_loadCEntropy(bs, workspace, offcodeNCount, &offcodeMaxValue, dict, dictSize);
|
||||||
|
|
||||||
|
dictPtr += 4; /* skip magic number */
|
||||||
|
dictID = params->fParams.noDictIDFlag ? 0 : MEM_readLE32(dictPtr);
|
||||||
|
dictPtr += 4;
|
||||||
|
|
||||||
|
dictPtr += eSize - 8; /* size of header + magic number already accounted for */
|
||||||
|
|
||||||
{ size_t const dictContentSize = (size_t)(dictEnd - dictPtr);
|
{ size_t const dictContentSize = (size_t)(dictEnd - dictPtr);
|
||||||
U32 offcodeMax = MaxOff;
|
U32 offcodeMax = MaxOff;
|
||||||
|
|||||||
@@ -930,7 +930,17 @@ MEM_STATIC void ZSTD_debugTable(const U32* table, U32 max)
|
|||||||
#if defined (__cplusplus)
|
#if defined (__cplusplus)
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
/* ===============================================================
|
||||||
|
* Public declarations
|
||||||
|
* These prototypes may be called from sources not in lib/compress
|
||||||
|
* =============================================================== */
|
||||||
|
|
||||||
|
/* ZSTD_loadCEntropy() :
|
||||||
|
* dict : must point at beginning of a valid zstd dictionary.
|
||||||
|
* return : size of entropy tables read */
|
||||||
|
size_t ZSTD_loadCEntropy(ZSTD_compressedBlockState_t* bs, void* workspace,
|
||||||
|
short* offcodeNCount, unsigned* offcodeMaxValue,
|
||||||
|
const void* const dict, size_t dictSize);
|
||||||
|
|
||||||
/* ==============================================================
|
/* ==============================================================
|
||||||
* Private declarations
|
* Private declarations
|
||||||
|
|||||||
Reference in New Issue
Block a user