77{
79 size_t const lhSize = 3 + (srcSize >= 1
KB) + (srcSize >= 16
KB);
81 U32 singleStream = srcSize < 256;
83 size_t cLitSize;
84
85 DEBUGLOG(5,
"ZSTD_compressLiterals (disableLiteralCompression=%i srcSize=%u)",
86 disableLiteralCompression, (
U32)srcSize);
87
88
89 memcpy(nextHuf, prevHuf,
sizeof(*prevHuf));
90
91 if (disableLiteralCompression)
93
94
95# define COMPRESS_LITERALS_SIZE_MIN 63
98 }
99
100 RETURN_ERROR_IF(dstCapacity < lhSize+1, dstSize_tooSmall,
"not enough space for compression");
101 { HUF_repeat
repeat = prevHuf->repeatMode;
102 int const preferRepeat = strategy <
ZSTD_lazy ? srcSize <= 1024 : 0;
103 if (
repeat == HUF_repeat_valid && lhSize == 3) singleStream = 1;
104 cLitSize = singleStream ?
106 ostart+lhSize, dstCapacity-lhSize,
src, srcSize,
107 HUF_SYMBOLVALUE_MAX, HUF_TABLELOG_DEFAULT, entropyWorkspace, entropyWorkspaceSize,
108 (HUF_CElt*)nextHuf->
CTable, &
repeat, preferRepeat, bmi2) :
110 ostart+lhSize, dstCapacity-lhSize,
src, srcSize,
111 HUF_SYMBOLVALUE_MAX, HUF_TABLELOG_DEFAULT, entropyWorkspace, entropyWorkspaceSize,
112 (HUF_CElt*)nextHuf->CTable, &
repeat, preferRepeat, bmi2);
113 if (
repeat != HUF_repeat_none) {
114
115 DEBUGLOG(5,
"Reusing previous huffman table");
117 }
118 }
119
120 if ((cLitSize==0) | (cLitSize >= srcSize - minGain) |
ERR_isError(cLitSize)) {
121 memcpy(nextHuf, prevHuf,
sizeof(*prevHuf));
123 }
124 if (cLitSize==1) {
125 memcpy(nextHuf, prevHuf,
sizeof(*prevHuf));
127 }
128
130
132 }
133
134
135 switch(lhSize)
136 {
137 case 3:
138 {
U32 const lhc = hType + ((!singleStream) << 2) + ((
U32)srcSize<<4) + ((
U32)cLitSize<<14);
140 break;
141 }
142 case 4:
143 {
U32 const lhc = hType + (2 << 2) + ((
U32)srcSize<<4) + ((
U32)cLitSize<<18);
145 break;
146 }
147 case 5:
148 {
U32 const lhc = hType + (3 << 2) + ((
U32)srcSize<<4) + ((
U32)cLitSize<<22);
150 ostart[4] = (
BYTE)(cLitSize >> 10);
151 break;
152 }
153 default:
155 }
156 DEBUGLOG(5,
"Compressed literals: %u -> %u", (
U32)srcSize, (
U32)(lhSize+cLitSize));
157 return lhSize+cLitSize;
158}
MEM_STATIC void MEM_writeLE32(void *memPtr, U32 val32)
MEM_STATIC void MEM_writeLE24(void *memPtr, U32 val)
ERR_STATIC unsigned ERR_isError(size_t code)
size_t HUF_compress4X_repeat(void *dst, size_t dstSize, const void *src, size_t srcSize, unsigned maxSymbolValue, unsigned huffLog, void *workSpace, size_t wkspSize, HUF_CElt *hufTable, HUF_repeat *repeat, int preferRepeat, int bmi2)
size_t HUF_compress1X_repeat(void *dst, size_t dstSize, const void *src, size_t srcSize, unsigned maxSymbolValue, unsigned huffLog, void *workSpace, size_t wkspSize, HUF_CElt *hufTable, HUF_repeat *repeat, int preferRepeat, int bmi2)
#define memcpy(s1, s2, n)
U32 CTable[HUF_CTABLE_SIZE_U32(255)]
MEM_STATIC size_t ZSTD_minGain(size_t srcSize, ZSTD_strategy strat)
size_t ZSTD_noCompressLiterals(void *dst, size_t dstCapacity, const void *src, size_t srcSize)
#define COMPRESS_LITERALS_SIZE_MIN
size_t ZSTD_compressRleLiteralsBlock(void *dst, size_t dstCapacity, const void *src, size_t srcSize)
#define RETURN_ERROR_IF(cond, err,...)