zstd-ruby 1.4.5.0 → 1.4.9.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/ruby.yml +35 -0
- data/README.md +2 -2
- data/ext/zstdruby/libzstd/Makefile +237 -138
- data/ext/zstdruby/libzstd/README.md +28 -0
- data/ext/zstdruby/libzstd/common/bitstream.h +25 -16
- data/ext/zstdruby/libzstd/common/compiler.h +118 -4
- data/ext/zstdruby/libzstd/common/cpu.h +1 -3
- data/ext/zstdruby/libzstd/common/debug.c +1 -1
- data/ext/zstdruby/libzstd/common/debug.h +12 -19
- data/ext/zstdruby/libzstd/common/entropy_common.c +189 -43
- data/ext/zstdruby/libzstd/common/error_private.c +2 -1
- data/ext/zstdruby/libzstd/common/error_private.h +2 -2
- data/ext/zstdruby/libzstd/common/fse.h +40 -12
- data/ext/zstdruby/libzstd/common/fse_decompress.c +124 -17
- data/ext/zstdruby/libzstd/common/huf.h +27 -6
- data/ext/zstdruby/libzstd/common/mem.h +67 -94
- data/ext/zstdruby/libzstd/common/pool.c +23 -17
- data/ext/zstdruby/libzstd/common/pool.h +2 -2
- data/ext/zstdruby/libzstd/common/threading.c +6 -5
- data/ext/zstdruby/libzstd/common/xxhash.c +19 -57
- data/ext/zstdruby/libzstd/common/xxhash.h +2 -2
- data/ext/zstdruby/libzstd/common/zstd_common.c +10 -10
- data/ext/zstdruby/libzstd/common/zstd_deps.h +111 -0
- data/ext/zstdruby/libzstd/common/zstd_errors.h +2 -1
- data/ext/zstdruby/libzstd/common/zstd_internal.h +90 -59
- data/ext/zstdruby/libzstd/common/zstd_trace.c +42 -0
- data/ext/zstdruby/libzstd/common/zstd_trace.h +152 -0
- data/ext/zstdruby/libzstd/compress/fse_compress.c +31 -24
- data/ext/zstdruby/libzstd/compress/hist.c +27 -29
- data/ext/zstdruby/libzstd/compress/hist.h +2 -2
- data/ext/zstdruby/libzstd/compress/huf_compress.c +217 -101
- data/ext/zstdruby/libzstd/compress/zstd_compress.c +1495 -478
- data/ext/zstdruby/libzstd/compress/zstd_compress_internal.h +143 -44
- data/ext/zstdruby/libzstd/compress/zstd_compress_literals.c +7 -7
- data/ext/zstdruby/libzstd/compress/zstd_compress_literals.h +1 -1
- data/ext/zstdruby/libzstd/compress/zstd_compress_sequences.c +18 -4
- data/ext/zstdruby/libzstd/compress/zstd_compress_sequences.h +1 -1
- data/ext/zstdruby/libzstd/compress/zstd_compress_superblock.c +25 -21
- data/ext/zstdruby/libzstd/compress/zstd_compress_superblock.h +1 -1
- data/ext/zstdruby/libzstd/compress/zstd_cwksp.h +62 -26
- data/ext/zstdruby/libzstd/compress/zstd_double_fast.c +23 -23
- data/ext/zstdruby/libzstd/compress/zstd_double_fast.h +1 -1
- data/ext/zstdruby/libzstd/compress/zstd_fast.c +21 -21
- data/ext/zstdruby/libzstd/compress/zstd_fast.h +1 -1
- data/ext/zstdruby/libzstd/compress/zstd_lazy.c +352 -78
- data/ext/zstdruby/libzstd/compress/zstd_lazy.h +21 -1
- data/ext/zstdruby/libzstd/compress/zstd_ldm.c +276 -209
- data/ext/zstdruby/libzstd/compress/zstd_ldm.h +8 -2
- data/ext/zstdruby/libzstd/compress/zstd_ldm_geartab.h +103 -0
- data/ext/zstdruby/libzstd/compress/zstd_opt.c +191 -46
- data/ext/zstdruby/libzstd/compress/zstd_opt.h +1 -1
- data/ext/zstdruby/libzstd/compress/zstdmt_compress.c +79 -410
- data/ext/zstdruby/libzstd/compress/zstdmt_compress.h +27 -109
- data/ext/zstdruby/libzstd/decompress/huf_decompress.c +303 -201
- data/ext/zstdruby/libzstd/decompress/zstd_ddict.c +9 -9
- data/ext/zstdruby/libzstd/decompress/zstd_ddict.h +2 -2
- data/ext/zstdruby/libzstd/decompress/zstd_decompress.c +370 -87
- data/ext/zstdruby/libzstd/decompress/zstd_decompress_block.c +153 -45
- data/ext/zstdruby/libzstd/decompress/zstd_decompress_block.h +6 -3
- data/ext/zstdruby/libzstd/decompress/zstd_decompress_internal.h +28 -11
- data/ext/zstdruby/libzstd/deprecated/zbuff.h +1 -1
- data/ext/zstdruby/libzstd/deprecated/zbuff_common.c +1 -1
- data/ext/zstdruby/libzstd/deprecated/zbuff_compress.c +1 -1
- data/ext/zstdruby/libzstd/deprecated/zbuff_decompress.c +1 -1
- data/ext/zstdruby/libzstd/dictBuilder/cover.c +40 -31
- data/ext/zstdruby/libzstd/dictBuilder/cover.h +2 -2
- data/ext/zstdruby/libzstd/dictBuilder/divsufsort.c +1 -1
- data/ext/zstdruby/libzstd/dictBuilder/fastcover.c +26 -25
- data/ext/zstdruby/libzstd/dictBuilder/zdict.c +22 -24
- data/ext/zstdruby/libzstd/dictBuilder/zdict.h +5 -4
- data/ext/zstdruby/libzstd/dll/example/Makefile +1 -1
- data/ext/zstdruby/libzstd/dll/example/README.md +16 -22
- data/ext/zstdruby/libzstd/legacy/zstd_legacy.h +1 -1
- data/ext/zstdruby/libzstd/legacy/zstd_v01.c +6 -2
- data/ext/zstdruby/libzstd/legacy/zstd_v01.h +1 -1
- data/ext/zstdruby/libzstd/legacy/zstd_v02.c +6 -2
- data/ext/zstdruby/libzstd/legacy/zstd_v02.h +1 -1
- data/ext/zstdruby/libzstd/legacy/zstd_v03.c +6 -2
- data/ext/zstdruby/libzstd/legacy/zstd_v03.h +1 -1
- data/ext/zstdruby/libzstd/legacy/zstd_v04.c +7 -3
- data/ext/zstdruby/libzstd/legacy/zstd_v04.h +1 -1
- data/ext/zstdruby/libzstd/legacy/zstd_v05.c +10 -6
- data/ext/zstdruby/libzstd/legacy/zstd_v05.h +1 -1
- data/ext/zstdruby/libzstd/legacy/zstd_v06.c +10 -6
- data/ext/zstdruby/libzstd/legacy/zstd_v06.h +1 -1
- data/ext/zstdruby/libzstd/legacy/zstd_v07.c +10 -6
- data/ext/zstdruby/libzstd/legacy/zstd_v07.h +1 -1
- data/ext/zstdruby/libzstd/libzstd.pc.in +3 -3
- data/ext/zstdruby/libzstd/zstd.h +414 -54
- data/lib/zstd-ruby/version.rb +1 -1
- metadata +7 -3
- data/.travis.yml +0 -14
@@ -1,5 +1,5 @@
|
|
1
1
|
/*
|
2
|
-
* Copyright (c) 2016-
|
2
|
+
* Copyright (c) 2016-2021, Yann Collet, Facebook, Inc.
|
3
3
|
* All rights reserved.
|
4
4
|
*
|
5
5
|
* This source code is licensed under both the BSD-style license (found in the
|
@@ -19,6 +19,7 @@
|
|
19
19
|
* Dependencies
|
20
20
|
***************************************/
|
21
21
|
#include "../common/zstd_internal.h"
|
22
|
+
#include "../common/zstd_trace.h" /* ZSTD_TraceCtx */
|
22
23
|
#include "zstd_cwksp.h"
|
23
24
|
#ifdef ZSTD_MULTITHREAD
|
24
25
|
# include "zstdmt_compress.h"
|
@@ -28,7 +29,6 @@
|
|
28
29
|
extern "C" {
|
29
30
|
#endif
|
30
31
|
|
31
|
-
|
32
32
|
/*-*************************************
|
33
33
|
* Constants
|
34
34
|
***************************************/
|
@@ -64,7 +64,7 @@ typedef struct {
|
|
64
64
|
} ZSTD_localDict;
|
65
65
|
|
66
66
|
typedef struct {
|
67
|
-
|
67
|
+
HUF_CElt CTable[HUF_CTABLE_SIZE_U32(255)];
|
68
68
|
HUF_repeat repeatMode;
|
69
69
|
} ZSTD_hufCTables_t;
|
70
70
|
|
@@ -83,10 +83,27 @@ typedef struct {
|
|
83
83
|
} ZSTD_entropyCTables_t;
|
84
84
|
|
85
85
|
typedef struct {
|
86
|
-
U32 off;
|
87
|
-
U32 len;
|
86
|
+
U32 off; /* Offset code (offset + ZSTD_REP_MOVE) for the match */
|
87
|
+
U32 len; /* Raw length of match */
|
88
88
|
} ZSTD_match_t;
|
89
89
|
|
90
|
+
typedef struct {
|
91
|
+
U32 offset; /* Offset of sequence */
|
92
|
+
U32 litLength; /* Length of literals prior to match */
|
93
|
+
U32 matchLength; /* Raw length of match */
|
94
|
+
} rawSeq;
|
95
|
+
|
96
|
+
typedef struct {
|
97
|
+
rawSeq* seq; /* The start of the sequences */
|
98
|
+
size_t pos; /* The index in seq where reading stopped. pos <= size. */
|
99
|
+
size_t posInSequence; /* The position within the sequence at seq[pos] where reading
|
100
|
+
stopped. posInSequence <= seq[pos].litLength + seq[pos].matchLength */
|
101
|
+
size_t size; /* The number of sequences. <= capacity. */
|
102
|
+
size_t capacity; /* The capacity starting from `seq` pointer */
|
103
|
+
} rawSeqStore_t;
|
104
|
+
|
105
|
+
UNUSED_ATTR static const rawSeqStore_t kNullRawSeqStore = {NULL, 0, 0, 0, 0};
|
106
|
+
|
90
107
|
typedef struct {
|
91
108
|
int price;
|
92
109
|
U32 off;
|
@@ -147,9 +164,13 @@ struct ZSTD_matchState_t {
|
|
147
164
|
U32* hashTable;
|
148
165
|
U32* hashTable3;
|
149
166
|
U32* chainTable;
|
167
|
+
int dedicatedDictSearch; /* Indicates whether this matchState is using the
|
168
|
+
* dedicated dictionary search structure.
|
169
|
+
*/
|
150
170
|
optState_t opt; /* optimal parser state */
|
151
171
|
const ZSTD_matchState_t* dictMatchState;
|
152
172
|
ZSTD_compressionParameters cParams;
|
173
|
+
const rawSeqStore_t* ldmSeqStore;
|
153
174
|
};
|
154
175
|
|
155
176
|
typedef struct {
|
@@ -163,13 +184,22 @@ typedef struct {
|
|
163
184
|
U32 checksum;
|
164
185
|
} ldmEntry_t;
|
165
186
|
|
187
|
+
typedef struct {
|
188
|
+
BYTE const* split;
|
189
|
+
U32 hash;
|
190
|
+
U32 checksum;
|
191
|
+
ldmEntry_t* bucket;
|
192
|
+
} ldmMatchCandidate_t;
|
193
|
+
|
194
|
+
#define LDM_BATCH_SIZE 64
|
195
|
+
|
166
196
|
typedef struct {
|
167
197
|
ZSTD_window_t window; /* State for the window round buffer management */
|
168
198
|
ldmEntry_t* hashTable;
|
169
199
|
U32 loadedDictEnd;
|
170
200
|
BYTE* bucketOffsets; /* Next position in bucket to insert entry */
|
171
|
-
|
172
|
-
|
201
|
+
size_t splitIndices[LDM_BATCH_SIZE];
|
202
|
+
ldmMatchCandidate_t matchCandidates[LDM_BATCH_SIZE];
|
173
203
|
} ldmState_t;
|
174
204
|
|
175
205
|
typedef struct {
|
@@ -181,19 +211,6 @@ typedef struct {
|
|
181
211
|
U32 windowLog; /* Window log for the LDM */
|
182
212
|
} ldmParams_t;
|
183
213
|
|
184
|
-
typedef struct {
|
185
|
-
U32 offset;
|
186
|
-
U32 litLength;
|
187
|
-
U32 matchLength;
|
188
|
-
} rawSeq;
|
189
|
-
|
190
|
-
typedef struct {
|
191
|
-
rawSeq* seq; /* The start of the sequences */
|
192
|
-
size_t pos; /* The position where reading stopped. <= size. */
|
193
|
-
size_t size; /* The number of sequences. <= capacity. */
|
194
|
-
size_t capacity; /* The capacity starting from `seq` pointer */
|
195
|
-
} rawSeqStore_t;
|
196
|
-
|
197
214
|
typedef struct {
|
198
215
|
int collectSequences;
|
199
216
|
ZSTD_Sequence* seqStart;
|
@@ -228,10 +245,34 @@ struct ZSTD_CCtx_params_s {
|
|
228
245
|
/* Long distance matching parameters */
|
229
246
|
ldmParams_t ldmParams;
|
230
247
|
|
248
|
+
/* Dedicated dict search algorithm trigger */
|
249
|
+
int enableDedicatedDictSearch;
|
250
|
+
|
251
|
+
/* Input/output buffer modes */
|
252
|
+
ZSTD_bufferMode_e inBufferMode;
|
253
|
+
ZSTD_bufferMode_e outBufferMode;
|
254
|
+
|
255
|
+
/* Sequence compression API */
|
256
|
+
ZSTD_sequenceFormat_e blockDelimiters;
|
257
|
+
int validateSequences;
|
258
|
+
|
231
259
|
/* Internal use, for createCCtxParams() and freeCCtxParams() only */
|
232
260
|
ZSTD_customMem customMem;
|
233
261
|
}; /* typedef'd to ZSTD_CCtx_params within "zstd.h" */
|
234
262
|
|
263
|
+
#define COMPRESS_SEQUENCES_WORKSPACE_SIZE (sizeof(unsigned) * (MaxSeq + 2))
|
264
|
+
#define ENTROPY_WORKSPACE_SIZE (HUF_WORKSPACE_SIZE + COMPRESS_SEQUENCES_WORKSPACE_SIZE)
|
265
|
+
|
266
|
+
/**
|
267
|
+
* Indicates whether this compression proceeds directly from user-provided
|
268
|
+
* source buffer to user-provided destination buffer (ZSTDb_not_buffered), or
|
269
|
+
* whether the context needs to buffer the input/output (ZSTDb_buffered).
|
270
|
+
*/
|
271
|
+
typedef enum {
|
272
|
+
ZSTDb_not_buffered,
|
273
|
+
ZSTDb_buffered
|
274
|
+
} ZSTD_buffered_policy_e;
|
275
|
+
|
235
276
|
struct ZSTD_CCtx_s {
|
236
277
|
ZSTD_compressionStage_e stage;
|
237
278
|
int cParamsChanged; /* == 1 if cParams(except wlog) or compression level are changed in requestedParams. Triggers transmission of new params to ZSTDMT (if available) then reset to 0. */
|
@@ -239,6 +280,7 @@ struct ZSTD_CCtx_s {
|
|
239
280
|
ZSTD_CCtx_params requestedParams;
|
240
281
|
ZSTD_CCtx_params appliedParams;
|
241
282
|
U32 dictID;
|
283
|
+
size_t dictContentSize;
|
242
284
|
|
243
285
|
ZSTD_cwksp workspace; /* manages buffer for dynamic allocations */
|
244
286
|
size_t blockSize;
|
@@ -247,6 +289,7 @@ struct ZSTD_CCtx_s {
|
|
247
289
|
unsigned long long producedCSize;
|
248
290
|
XXH64_state_t xxhState;
|
249
291
|
ZSTD_customMem customMem;
|
292
|
+
ZSTD_threadPool* pool;
|
250
293
|
size_t staticSize;
|
251
294
|
SeqCollector seqCollector;
|
252
295
|
int isFirstBlock;
|
@@ -258,7 +301,10 @@ struct ZSTD_CCtx_s {
|
|
258
301
|
size_t maxNbLdmSequences;
|
259
302
|
rawSeqStore_t externSeqStore; /* Mutable reference to external sequences */
|
260
303
|
ZSTD_blockState_t blockState;
|
261
|
-
U32* entropyWorkspace; /* entropy workspace of
|
304
|
+
U32* entropyWorkspace; /* entropy workspace of ENTROPY_WORKSPACE_SIZE bytes */
|
305
|
+
|
306
|
+
/* Wether we are streaming or not */
|
307
|
+
ZSTD_buffered_policy_e bufferedPolicy;
|
262
308
|
|
263
309
|
/* streaming */
|
264
310
|
char* inBuff;
|
@@ -273,6 +319,10 @@ struct ZSTD_CCtx_s {
|
|
273
319
|
ZSTD_cStreamStage streamStage;
|
274
320
|
U32 frameEnded;
|
275
321
|
|
322
|
+
/* Stable in/out buffer verification */
|
323
|
+
ZSTD_inBuffer expectedInBuffer;
|
324
|
+
size_t expectedOutBufferSize;
|
325
|
+
|
276
326
|
/* Dictionary */
|
277
327
|
ZSTD_localDict localDict;
|
278
328
|
const ZSTD_CDict* cdict;
|
@@ -282,12 +332,41 @@ struct ZSTD_CCtx_s {
|
|
282
332
|
#ifdef ZSTD_MULTITHREAD
|
283
333
|
ZSTDMT_CCtx* mtctx;
|
284
334
|
#endif
|
335
|
+
|
336
|
+
/* Tracing */
|
337
|
+
#if ZSTD_TRACE
|
338
|
+
ZSTD_TraceCtx traceCtx;
|
339
|
+
#endif
|
285
340
|
};
|
286
341
|
|
287
342
|
typedef enum { ZSTD_dtlm_fast, ZSTD_dtlm_full } ZSTD_dictTableLoadMethod_e;
|
288
343
|
|
289
|
-
typedef enum {
|
290
|
-
|
344
|
+
typedef enum {
|
345
|
+
ZSTD_noDict = 0,
|
346
|
+
ZSTD_extDict = 1,
|
347
|
+
ZSTD_dictMatchState = 2,
|
348
|
+
ZSTD_dedicatedDictSearch = 3
|
349
|
+
} ZSTD_dictMode_e;
|
350
|
+
|
351
|
+
typedef enum {
|
352
|
+
ZSTD_cpm_noAttachDict = 0, /* Compression with ZSTD_noDict or ZSTD_extDict.
|
353
|
+
* In this mode we use both the srcSize and the dictSize
|
354
|
+
* when selecting and adjusting parameters.
|
355
|
+
*/
|
356
|
+
ZSTD_cpm_attachDict = 1, /* Compression with ZSTD_dictMatchState or ZSTD_dedicatedDictSearch.
|
357
|
+
* In this mode we only take the srcSize into account when selecting
|
358
|
+
* and adjusting parameters.
|
359
|
+
*/
|
360
|
+
ZSTD_cpm_createCDict = 2, /* Creating a CDict.
|
361
|
+
* In this mode we take both the source size and the dictionary size
|
362
|
+
* into account when selecting and adjusting the parameters.
|
363
|
+
*/
|
364
|
+
ZSTD_cpm_unknown = 3, /* ZSTD_getCParams, ZSTD_getParams, ZSTD_adjustParams.
|
365
|
+
* We don't know what these parameters are for. We default to the legacy
|
366
|
+
* behavior of taking both the source size and the dict size into account
|
367
|
+
* when selecting and adjusting parameters.
|
368
|
+
*/
|
369
|
+
} ZSTD_cParamMode_e;
|
291
370
|
|
292
371
|
typedef size_t (*ZSTD_blockCompressor) (
|
293
372
|
ZSTD_matchState_t* bs, seqStore_t* seqStore, U32 rep[ZSTD_REP_NUM],
|
@@ -345,7 +424,7 @@ MEM_STATIC repcodes_t ZSTD_updateRep(U32 const rep[3], U32 const offset, U32 con
|
|
345
424
|
newReps.rep[1] = rep[0];
|
346
425
|
newReps.rep[0] = currentOffset;
|
347
426
|
} else { /* repCode == 0 */
|
348
|
-
|
427
|
+
ZSTD_memcpy(&newReps, rep, sizeof(newReps));
|
349
428
|
}
|
350
429
|
}
|
351
430
|
return newReps;
|
@@ -372,7 +451,7 @@ MEM_STATIC size_t ZSTD_noCompressBlock (void* dst, size_t dstCapacity, const voi
|
|
372
451
|
RETURN_ERROR_IF(srcSize + ZSTD_blockHeaderSize > dstCapacity,
|
373
452
|
dstSize_tooSmall, "dst buf too small for uncompressed block");
|
374
453
|
MEM_writeLE24(dst, cBlockHeader24);
|
375
|
-
|
454
|
+
ZSTD_memcpy((BYTE*)dst + ZSTD_blockHeaderSize, src, srcSize);
|
376
455
|
return ZSTD_blockHeaderSize + srcSize;
|
377
456
|
}
|
378
457
|
|
@@ -498,8 +577,12 @@ static unsigned ZSTD_NbCommonBytes (size_t val)
|
|
498
577
|
if (MEM_isLittleEndian()) {
|
499
578
|
if (MEM_64bits()) {
|
500
579
|
# if defined(_MSC_VER) && defined(_WIN64)
|
501
|
-
|
502
|
-
|
580
|
+
# if STATIC_BMI2
|
581
|
+
return _tzcnt_u64(val) >> 3;
|
582
|
+
# else
|
583
|
+
unsigned long r = 0;
|
584
|
+
return _BitScanForward64( &r, (U64)val ) ? (unsigned)(r >> 3) : 0;
|
585
|
+
# endif
|
503
586
|
# elif defined(__GNUC__) && (__GNUC__ >= 4)
|
504
587
|
return (__builtin_ctzll((U64)val) >> 3);
|
505
588
|
# else
|
@@ -530,8 +613,12 @@ static unsigned ZSTD_NbCommonBytes (size_t val)
|
|
530
613
|
} else { /* Big Endian CPU */
|
531
614
|
if (MEM_64bits()) {
|
532
615
|
# if defined(_MSC_VER) && defined(_WIN64)
|
533
|
-
|
534
|
-
|
616
|
+
# if STATIC_BMI2
|
617
|
+
return _lzcnt_u64(val) >> 3;
|
618
|
+
# else
|
619
|
+
unsigned long r = 0;
|
620
|
+
return _BitScanReverse64(&r, (U64)val) ? (unsigned)(r >> 3) : 0;
|
621
|
+
# endif
|
535
622
|
# elif defined(__GNUC__) && (__GNUC__ >= 4)
|
536
623
|
return (__builtin_clzll(val) >> 3);
|
537
624
|
# else
|
@@ -626,7 +713,8 @@ static const U64 prime8bytes = 0xCF1BBCDCB7A56463ULL;
|
|
626
713
|
static size_t ZSTD_hash8(U64 u, U32 h) { return (size_t)(((u) * prime8bytes) >> (64-h)) ; }
|
627
714
|
static size_t ZSTD_hash8Ptr(const void* p, U32 h) { return ZSTD_hash8(MEM_readLE64(p), h); }
|
628
715
|
|
629
|
-
MEM_STATIC
|
716
|
+
MEM_STATIC FORCE_INLINE_ATTR
|
717
|
+
size_t ZSTD_hashPtr(const void* p, U32 hBits, U32 mls)
|
630
718
|
{
|
631
719
|
switch(mls)
|
632
720
|
{
|
@@ -742,7 +830,7 @@ MEM_STATIC ZSTD_dictMode_e ZSTD_matchState_dictMode(const ZSTD_matchState_t *ms)
|
|
742
830
|
return ZSTD_window_hasExtDict(ms->window) ?
|
743
831
|
ZSTD_extDict :
|
744
832
|
ms->dictMatchState != NULL ?
|
745
|
-
ZSTD_dictMatchState :
|
833
|
+
(ms->dictMatchState->dedicatedDictSearch ? ZSTD_dedicatedDictSearch : ZSTD_dictMatchState) :
|
746
834
|
ZSTD_noDict;
|
747
835
|
}
|
748
836
|
|
@@ -754,8 +842,8 @@ MEM_STATIC ZSTD_dictMode_e ZSTD_matchState_dictMode(const ZSTD_matchState_t *ms)
|
|
754
842
|
MEM_STATIC U32 ZSTD_window_needOverflowCorrection(ZSTD_window_t const window,
|
755
843
|
void const* srcEnd)
|
756
844
|
{
|
757
|
-
U32 const
|
758
|
-
return
|
845
|
+
U32 const curr = (U32)((BYTE const*)srcEnd - window.base);
|
846
|
+
return curr > ZSTD_CURRENT_MAX;
|
759
847
|
}
|
760
848
|
|
761
849
|
/**
|
@@ -791,14 +879,14 @@ MEM_STATIC U32 ZSTD_window_correctOverflow(ZSTD_window_t* window, U32 cycleLog,
|
|
791
879
|
* windowLog <= 31 ==> 3<<29 + 1<<windowLog < 7<<29 < 1<<32.
|
792
880
|
*/
|
793
881
|
U32 const cycleMask = (1U << cycleLog) - 1;
|
794
|
-
U32 const
|
795
|
-
U32 const currentCycle0 =
|
882
|
+
U32 const curr = (U32)((BYTE const*)src - window->base);
|
883
|
+
U32 const currentCycle0 = curr & cycleMask;
|
796
884
|
/* Exclude zero so that newCurrent - maxDist >= 1. */
|
797
885
|
U32 const currentCycle1 = currentCycle0 == 0 ? (1U << cycleLog) : currentCycle0;
|
798
886
|
U32 const newCurrent = currentCycle1 + maxDist;
|
799
|
-
U32 const correction =
|
887
|
+
U32 const correction = curr - newCurrent;
|
800
888
|
assert((maxDist & cycleMask) == 0);
|
801
|
-
assert(
|
889
|
+
assert(curr > newCurrent);
|
802
890
|
/* Loose bound, should be around 1<<29 (see above) */
|
803
891
|
assert(correction > 1<<28);
|
804
892
|
|
@@ -919,7 +1007,7 @@ ZSTD_checkDictValidity(const ZSTD_window_t* window,
|
|
919
1007
|
}
|
920
1008
|
|
921
1009
|
MEM_STATIC void ZSTD_window_init(ZSTD_window_t* window) {
|
922
|
-
|
1010
|
+
ZSTD_memset(window, 0, sizeof(*window));
|
923
1011
|
window->base = (BYTE const*)"";
|
924
1012
|
window->dictBase = (BYTE const*)"";
|
925
1013
|
window->dictLimit = 1; /* start from 1, so that 1st position is valid */
|
@@ -973,12 +1061,16 @@ MEM_STATIC U32 ZSTD_window_update(ZSTD_window_t* window,
|
|
973
1061
|
/**
|
974
1062
|
* Returns the lowest allowed match index. It may either be in the ext-dict or the prefix.
|
975
1063
|
*/
|
976
|
-
MEM_STATIC U32 ZSTD_getLowestMatchIndex(const ZSTD_matchState_t* ms, U32
|
1064
|
+
MEM_STATIC U32 ZSTD_getLowestMatchIndex(const ZSTD_matchState_t* ms, U32 curr, unsigned windowLog)
|
977
1065
|
{
|
978
1066
|
U32 const maxDistance = 1U << windowLog;
|
979
1067
|
U32 const lowestValid = ms->window.lowLimit;
|
980
|
-
U32 const withinWindow = (
|
1068
|
+
U32 const withinWindow = (curr - lowestValid > maxDistance) ? curr - maxDistance : lowestValid;
|
981
1069
|
U32 const isDictionary = (ms->loadedDictEnd != 0);
|
1070
|
+
/* When using a dictionary the entire dictionary is valid if a single byte of the dictionary
|
1071
|
+
* is within the window. We invalidate the dictionary (and set loadedDictEnd to 0) when it isn't
|
1072
|
+
* valid for the entire block. So this check is sufficient to find the lowest valid match index.
|
1073
|
+
*/
|
982
1074
|
U32 const matchLowest = isDictionary ? lowestValid : withinWindow;
|
983
1075
|
return matchLowest;
|
984
1076
|
}
|
@@ -986,12 +1078,15 @@ MEM_STATIC U32 ZSTD_getLowestMatchIndex(const ZSTD_matchState_t* ms, U32 current
|
|
986
1078
|
/**
|
987
1079
|
* Returns the lowest allowed match index in the prefix.
|
988
1080
|
*/
|
989
|
-
MEM_STATIC U32 ZSTD_getLowestPrefixIndex(const ZSTD_matchState_t* ms, U32
|
1081
|
+
MEM_STATIC U32 ZSTD_getLowestPrefixIndex(const ZSTD_matchState_t* ms, U32 curr, unsigned windowLog)
|
990
1082
|
{
|
991
1083
|
U32 const maxDistance = 1U << windowLog;
|
992
1084
|
U32 const lowestValid = ms->window.dictLimit;
|
993
|
-
U32 const withinWindow = (
|
1085
|
+
U32 const withinWindow = (curr - lowestValid > maxDistance) ? curr - maxDistance : lowestValid;
|
994
1086
|
U32 const isDictionary = (ms->loadedDictEnd != 0);
|
1087
|
+
/* When computing the lowest prefix index we need to take the dictionary into account to handle
|
1088
|
+
* the edge case where the dictionary and the source are contiguous in memory.
|
1089
|
+
*/
|
995
1090
|
U32 const matchLowest = isDictionary ? lowestValid : withinWindow;
|
996
1091
|
return matchLowest;
|
997
1092
|
}
|
@@ -1045,7 +1140,6 @@ MEM_STATIC void ZSTD_debugTable(const U32* table, U32 max)
|
|
1045
1140
|
* assumptions : magic number supposed already checked
|
1046
1141
|
* and dictSize >= 8 */
|
1047
1142
|
size_t ZSTD_loadCEntropy(ZSTD_compressedBlockState_t* bs, void* workspace,
|
1048
|
-
short* offcodeNCount, unsigned* offcodeMaxValue,
|
1049
1143
|
const void* const dict, size_t dictSize);
|
1050
1144
|
|
1051
1145
|
void ZSTD_reset_compressedBlockState(ZSTD_compressedBlockState_t* bs);
|
@@ -1061,7 +1155,7 @@ void ZSTD_reset_compressedBlockState(ZSTD_compressedBlockState_t* bs);
|
|
1061
1155
|
* Note: srcSizeHint == 0 means 0!
|
1062
1156
|
*/
|
1063
1157
|
ZSTD_compressionParameters ZSTD_getCParamsFromCCtxParams(
|
1064
|
-
const ZSTD_CCtx_params* CCtxParams, U64 srcSizeHint, size_t dictSize);
|
1158
|
+
const ZSTD_CCtx_params* CCtxParams, U64 srcSizeHint, size_t dictSize, ZSTD_cParamMode_e mode);
|
1065
1159
|
|
1066
1160
|
/*! ZSTD_initCStream_internal() :
|
1067
1161
|
* Private use only. Init streaming operation.
|
@@ -1122,4 +1216,9 @@ size_t ZSTD_referenceExternalSequences(ZSTD_CCtx* cctx, rawSeq* seq, size_t nbSe
|
|
1122
1216
|
* condition for correct operation : hashLog > 1 */
|
1123
1217
|
U32 ZSTD_cycleLog(U32 hashLog, ZSTD_strategy strat);
|
1124
1218
|
|
1219
|
+
/** ZSTD_CCtx_trace() :
|
1220
|
+
* Trace the end of a compression call.
|
1221
|
+
*/
|
1222
|
+
void ZSTD_CCtx_trace(ZSTD_CCtx* cctx, size_t extraCSize);
|
1223
|
+
|
1125
1224
|
#endif /* ZSTD_COMPRESS_H */
|
@@ -1,5 +1,5 @@
|
|
1
1
|
/*
|
2
|
-
* Copyright (c) 2016-
|
2
|
+
* Copyright (c) 2016-2021, Yann Collet, Facebook, Inc.
|
3
3
|
* All rights reserved.
|
4
4
|
*
|
5
5
|
* This source code is licensed under both the BSD-style license (found in the
|
@@ -15,7 +15,7 @@
|
|
15
15
|
|
16
16
|
size_t ZSTD_noCompressLiterals (void* dst, size_t dstCapacity, const void* src, size_t srcSize)
|
17
17
|
{
|
18
|
-
BYTE* const ostart = (BYTE*
|
18
|
+
BYTE* const ostart = (BYTE*)dst;
|
19
19
|
U32 const flSize = 1 + (srcSize>31) + (srcSize>4095);
|
20
20
|
|
21
21
|
RETURN_ERROR_IF(srcSize + flSize > dstCapacity, dstSize_tooSmall, "");
|
@@ -35,14 +35,14 @@ size_t ZSTD_noCompressLiterals (void* dst, size_t dstCapacity, const void* src,
|
|
35
35
|
assert(0);
|
36
36
|
}
|
37
37
|
|
38
|
-
|
38
|
+
ZSTD_memcpy(ostart + flSize, src, srcSize);
|
39
39
|
DEBUGLOG(5, "Raw literals: %u -> %u", (U32)srcSize, (U32)(srcSize + flSize));
|
40
40
|
return srcSize + flSize;
|
41
41
|
}
|
42
42
|
|
43
43
|
size_t ZSTD_compressRleLiteralsBlock (void* dst, size_t dstCapacity, const void* src, size_t srcSize)
|
44
44
|
{
|
45
|
-
BYTE* const ostart = (BYTE*
|
45
|
+
BYTE* const ostart = (BYTE*)dst;
|
46
46
|
U32 const flSize = 1 + (srcSize>31) + (srcSize>4095);
|
47
47
|
|
48
48
|
(void)dstCapacity; /* dstCapacity already guaranteed to be >=4, hence large enough */
|
@@ -86,7 +86,7 @@ size_t ZSTD_compressLiterals (ZSTD_hufCTables_t const* prevHuf,
|
|
86
86
|
disableLiteralCompression, (U32)srcSize);
|
87
87
|
|
88
88
|
/* Prepare nextEntropy assuming reusing the existing table */
|
89
|
-
|
89
|
+
ZSTD_memcpy(nextHuf, prevHuf, sizeof(*prevHuf));
|
90
90
|
|
91
91
|
if (disableLiteralCompression)
|
92
92
|
return ZSTD_noCompressLiterals(dst, dstCapacity, src, srcSize);
|
@@ -118,11 +118,11 @@ size_t ZSTD_compressLiterals (ZSTD_hufCTables_t const* prevHuf,
|
|
118
118
|
}
|
119
119
|
|
120
120
|
if ((cLitSize==0) | (cLitSize >= srcSize - minGain) | ERR_isError(cLitSize)) {
|
121
|
-
|
121
|
+
ZSTD_memcpy(nextHuf, prevHuf, sizeof(*prevHuf));
|
122
122
|
return ZSTD_noCompressLiterals(dst, dstCapacity, src, srcSize);
|
123
123
|
}
|
124
124
|
if (cLitSize==1) {
|
125
|
-
|
125
|
+
ZSTD_memcpy(nextHuf, prevHuf, sizeof(*prevHuf));
|
126
126
|
return ZSTD_compressRleLiteralsBlock(dst, dstCapacity, src, srcSize);
|
127
127
|
}
|
128
128
|
|