Integrated refactor into getDictHeaderSize, now passes tests
This commit is contained in:
parent
0bcaf6db08
commit
04fb42b4f3
@ -2772,8 +2772,8 @@ size_t ZSTD_loadCEntropy(ZSTD_compressedBlockState_t* bs, void* workspace,
|
|||||||
short* offcodeNCount, unsigned* offcodeMaxValue,
|
short* offcodeNCount, unsigned* offcodeMaxValue,
|
||||||
const void* const dict, size_t dictSize)
|
const void* const dict, size_t dictSize)
|
||||||
{
|
{
|
||||||
const BYTE* dictPtr = (const BYTE*)dict;
|
const BYTE* dictPtr = (const BYTE*)dict + 8;
|
||||||
const BYTE* const dictEnd = dictPtr + dictSize - 8;
|
const BYTE* const dictEnd = dictPtr + dictSize;
|
||||||
|
|
||||||
{ 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);
|
||||||
@ -2852,15 +2852,17 @@ static size_t ZSTD_loadZstdDictionary(ZSTD_compressedBlockState_t* bs,
|
|||||||
ZSTD_dictTableLoadMethod_e dtlm,
|
ZSTD_dictTableLoadMethod_e dtlm,
|
||||||
void* workspace)
|
void* workspace)
|
||||||
{
|
{
|
||||||
size_t dictID;
|
|
||||||
size_t eSize;
|
|
||||||
const BYTE* dictPtr = (const BYTE*)dict;
|
const BYTE* dictPtr = (const BYTE*)dict;
|
||||||
const BYTE* const dictEnd = dictPtr + dictSize;
|
const BYTE* const dictEnd = dictPtr + dictSize;
|
||||||
short offcodeNCount[MaxOff+1];
|
short offcodeNCount[MaxOff+1];
|
||||||
unsigned offcodeMaxValue = MaxOff;
|
unsigned offcodeMaxValue = MaxOff;
|
||||||
|
size_t dictID;
|
||||||
|
size_t eSize;
|
||||||
|
|
||||||
ZSTD_STATIC_ASSERT(HUF_WORKSPACE_SIZE >= (1<<MAX(MLFSELog,LLFSELog)));
|
ZSTD_STATIC_ASSERT(HUF_WORKSPACE_SIZE >= (1<<MAX(MLFSELog,LLFSELog)));
|
||||||
assert(dictSize > 8);
|
assert(dictSize > 8);
|
||||||
assert(MEM_readLE32(dictPtr) == ZSTD_MAGIC_DICTIONARY);
|
assert(MEM_readLE32(dictPtr) == ZSTD_MAGIC_DICTIONARY);
|
||||||
|
|
||||||
eSize = ZSTD_loadCEntropy(bs, workspace, offcodeNCount, &offcodeMaxValue, dict, dictSize);
|
eSize = ZSTD_loadCEntropy(bs, workspace, offcodeNCount, &offcodeMaxValue, dict, dictSize);
|
||||||
|
|
||||||
dictPtr += 4; /* skip magic number */
|
dictPtr += 4; /* skip magic number */
|
||||||
|
@ -48,7 +48,7 @@
|
|||||||
# define ZDICT_STATIC_LINKING_ONLY
|
# define ZDICT_STATIC_LINKING_ONLY
|
||||||
#endif
|
#endif
|
||||||
#include "zdict.h"
|
#include "zdict.h"
|
||||||
#include "decompress/zstd_decompress_internal.h" /* ZSTD_entropyDTables_t */
|
#include "compress/zstd_compress_internal.h" /* ZSTD_loadCEntropy() */
|
||||||
|
|
||||||
|
|
||||||
/*-*************************************
|
/*-*************************************
|
||||||
@ -105,14 +105,19 @@ size_t ZDICT_getDictHeaderSize(const void* dictBuffer, size_t dictSize)
|
|||||||
if (dictSize <= 8 || MEM_readLE32(dictBuffer) != ZSTD_MAGIC_DICTIONARY) return 0;
|
if (dictSize <= 8 || MEM_readLE32(dictBuffer) != ZSTD_MAGIC_DICTIONARY) return 0;
|
||||||
|
|
||||||
{ size_t headerSize;
|
{ size_t headerSize;
|
||||||
ZSTD_entropyDTables_t* dummyEntropyTables = (ZSTD_entropyDTables_t*)malloc(sizeof(ZSTD_entropyDTables_t));
|
unsigned offcodeMaxValue = MaxOff;
|
||||||
if (!dummyEntropyTables) {
|
ZSTD_compressedBlockState_t* dummyBs = (ZSTD_compressedBlockState_t*)malloc(sizeof(ZSTD_compressedBlockState_t));
|
||||||
|
U32* wksp = (U32*)malloc(HUF_WORKSPACE_SIZE);
|
||||||
|
short* offcodeNCount = (short*)malloc((MaxOff+1)*sizeof(short));
|
||||||
|
if (!dummyBs || !wksp) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
dummyEntropyTables->hufTable[0] = (HUF_DTable)((HufLog)*0x1000001);
|
|
||||||
headerSize = ZSTD_loadDEntropy(dummyEntropyTables, dictBuffer, dictSize);
|
headerSize = ZSTD_loadCEntropy(dummyBs, wksp, offcodeNCount, &offcodeMaxValue, dictBuffer, dictSize);
|
||||||
free(dummyEntropyTables);
|
free(dummyBs);
|
||||||
return ZSTD_isError(headerSize) ? 0 : headerSize;
|
free(wksp);
|
||||||
|
free(offcodeNCount);
|
||||||
|
return headerSize;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user