zstd-ruby 1.3.7.0 → 1.3.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/ext/zstdruby/libzstd/BUCK +15 -2
- data/ext/zstdruby/libzstd/Makefile +37 -2
- data/ext/zstdruby/libzstd/README.md +67 -41
- data/ext/zstdruby/libzstd/common/bitstream.h +2 -2
- data/ext/zstdruby/libzstd/common/compiler.h +19 -12
- data/ext/zstdruby/libzstd/common/cpu.h +1 -1
- data/ext/zstdruby/libzstd/common/debug.h +22 -11
- data/ext/zstdruby/libzstd/common/error_private.c +6 -0
- data/ext/zstdruby/libzstd/common/fse.h +2 -2
- data/ext/zstdruby/libzstd/common/huf.h +25 -1
- data/ext/zstdruby/libzstd/common/pool.c +1 -1
- data/ext/zstdruby/libzstd/common/zstd_common.c +3 -1
- data/ext/zstdruby/libzstd/common/zstd_errors.h +1 -0
- data/ext/zstdruby/libzstd/common/zstd_internal.h +11 -2
- data/ext/zstdruby/libzstd/compress/fse_compress.c +3 -3
- data/ext/zstdruby/libzstd/compress/hist.c +19 -11
- data/ext/zstdruby/libzstd/compress/hist.h +11 -8
- data/ext/zstdruby/libzstd/compress/huf_compress.c +33 -31
- data/ext/zstdruby/libzstd/compress/zstd_compress.c +621 -371
- data/ext/zstdruby/libzstd/compress/zstd_compress_internal.h +90 -28
- data/ext/zstdruby/libzstd/compress/zstd_double_fast.c +4 -4
- data/ext/zstdruby/libzstd/compress/zstd_fast.c +15 -15
- data/ext/zstdruby/libzstd/compress/zstd_lazy.c +25 -18
- data/ext/zstdruby/libzstd/compress/zstd_ldm.c +18 -67
- data/ext/zstdruby/libzstd/compress/zstd_ldm.h +2 -6
- data/ext/zstdruby/libzstd/compress/zstd_opt.c +133 -48
- data/ext/zstdruby/libzstd/compress/zstd_opt.h +8 -0
- data/ext/zstdruby/libzstd/compress/zstdmt_compress.c +229 -73
- data/ext/zstdruby/libzstd/compress/zstdmt_compress.h +18 -10
- data/ext/zstdruby/libzstd/decompress/huf_decompress.c +178 -42
- data/ext/zstdruby/libzstd/decompress/zstd_ddict.c +240 -0
- data/ext/zstdruby/libzstd/decompress/zstd_ddict.h +44 -0
- data/ext/zstdruby/libzstd/decompress/zstd_decompress.c +244 -1680
- data/ext/zstdruby/libzstd/decompress/zstd_decompress_block.c +1307 -0
- data/ext/zstdruby/libzstd/decompress/zstd_decompress_block.h +59 -0
- data/ext/zstdruby/libzstd/decompress/zstd_decompress_internal.h +168 -0
- data/ext/zstdruby/libzstd/dictBuilder/cover.c +13 -11
- data/ext/zstdruby/libzstd/dictBuilder/fastcover.c +15 -15
- data/ext/zstdruby/libzstd/dictBuilder/zdict.c +28 -28
- data/ext/zstdruby/libzstd/dll/libzstd.def +0 -1
- data/ext/zstdruby/libzstd/legacy/zstd_v04.c +0 -10
- data/ext/zstdruby/libzstd/legacy/zstd_v05.c +15 -15
- data/ext/zstdruby/libzstd/zstd.h +1208 -968
- data/lib/zstd-ruby/version.rb +1 -1
- metadata +7 -2
@@ -48,12 +48,6 @@ extern "C" {
|
|
48
48
|
typedef enum { ZSTDcs_created=0, ZSTDcs_init, ZSTDcs_ongoing, ZSTDcs_ending } ZSTD_compressionStage_e;
|
49
49
|
typedef enum { zcss_init=0, zcss_load, zcss_flush } ZSTD_cStreamStage;
|
50
50
|
|
51
|
-
typedef enum {
|
52
|
-
ZSTD_dictDefaultAttach = 0,
|
53
|
-
ZSTD_dictForceAttach = 1,
|
54
|
-
ZSTD_dictForceCopy = -1,
|
55
|
-
} ZSTD_dictAttachPref_e;
|
56
|
-
|
57
51
|
typedef struct ZSTD_prefixDict_s {
|
58
52
|
const void* dict;
|
59
53
|
size_t dictSize;
|
@@ -96,10 +90,10 @@ typedef enum { zop_dynamic=0, zop_predef } ZSTD_OptPrice_e;
|
|
96
90
|
|
97
91
|
typedef struct {
|
98
92
|
/* All tables are allocated inside cctx->workspace by ZSTD_resetCCtx_internal() */
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
93
|
+
unsigned* litFreq; /* table of literals statistics, of size 256 */
|
94
|
+
unsigned* litLengthFreq; /* table of litLength statistics, of size (MaxLL+1) */
|
95
|
+
unsigned* matchLengthFreq; /* table of matchLength statistics, of size (MaxML+1) */
|
96
|
+
unsigned* offCodeFreq; /* table of offCode statistics, of size (MaxOff+1) */
|
103
97
|
ZSTD_match_t* matchTable; /* list of found matches, of size ZSTD_OPT_NUM+1 */
|
104
98
|
ZSTD_optimal_t* priceTable; /* All positions tracked by optimal parser, of size ZSTD_OPT_NUM+1 */
|
105
99
|
|
@@ -139,7 +133,7 @@ struct ZSTD_matchState_t {
|
|
139
133
|
U32* hashTable3;
|
140
134
|
U32* chainTable;
|
141
135
|
optState_t opt; /* optimal parser state */
|
142
|
-
const ZSTD_matchState_t *dictMatchState;
|
136
|
+
const ZSTD_matchState_t * dictMatchState;
|
143
137
|
ZSTD_compressionParameters cParams;
|
144
138
|
};
|
145
139
|
|
@@ -167,7 +161,7 @@ typedef struct {
|
|
167
161
|
U32 hashLog; /* Log size of hashTable */
|
168
162
|
U32 bucketSizeLog; /* Log bucket size for collision resolution, at most 8 */
|
169
163
|
U32 minMatchLength; /* Minimum match length */
|
170
|
-
U32
|
164
|
+
U32 hashRateLog; /* Log number of entries to skip */
|
171
165
|
U32 windowLog; /* Window log for the LDM */
|
172
166
|
} ldmParams_t;
|
173
167
|
|
@@ -196,9 +190,10 @@ struct ZSTD_CCtx_params_s {
|
|
196
190
|
ZSTD_dictAttachPref_e attachDictPref;
|
197
191
|
|
198
192
|
/* Multithreading: used to pass parameters to mtctx */
|
199
|
-
|
200
|
-
|
201
|
-
|
193
|
+
int nbWorkers;
|
194
|
+
size_t jobSize;
|
195
|
+
int overlapLog;
|
196
|
+
int rsyncable;
|
202
197
|
|
203
198
|
/* Long distance matching parameters */
|
204
199
|
ldmParams_t ldmParams;
|
@@ -498,6 +493,64 @@ MEM_STATIC size_t ZSTD_hashPtr(const void* p, U32 hBits, U32 mls)
|
|
498
493
|
}
|
499
494
|
}
|
500
495
|
|
496
|
+
/** ZSTD_ipow() :
|
497
|
+
* Return base^exponent.
|
498
|
+
*/
|
499
|
+
static U64 ZSTD_ipow(U64 base, U64 exponent)
|
500
|
+
{
|
501
|
+
U64 power = 1;
|
502
|
+
while (exponent) {
|
503
|
+
if (exponent & 1) power *= base;
|
504
|
+
exponent >>= 1;
|
505
|
+
base *= base;
|
506
|
+
}
|
507
|
+
return power;
|
508
|
+
}
|
509
|
+
|
510
|
+
#define ZSTD_ROLL_HASH_CHAR_OFFSET 10
|
511
|
+
|
512
|
+
/** ZSTD_rollingHash_append() :
|
513
|
+
* Add the buffer to the hash value.
|
514
|
+
*/
|
515
|
+
static U64 ZSTD_rollingHash_append(U64 hash, void const* buf, size_t size)
|
516
|
+
{
|
517
|
+
BYTE const* istart = (BYTE const*)buf;
|
518
|
+
size_t pos;
|
519
|
+
for (pos = 0; pos < size; ++pos) {
|
520
|
+
hash *= prime8bytes;
|
521
|
+
hash += istart[pos] + ZSTD_ROLL_HASH_CHAR_OFFSET;
|
522
|
+
}
|
523
|
+
return hash;
|
524
|
+
}
|
525
|
+
|
526
|
+
/** ZSTD_rollingHash_compute() :
|
527
|
+
* Compute the rolling hash value of the buffer.
|
528
|
+
*/
|
529
|
+
MEM_STATIC U64 ZSTD_rollingHash_compute(void const* buf, size_t size)
|
530
|
+
{
|
531
|
+
return ZSTD_rollingHash_append(0, buf, size);
|
532
|
+
}
|
533
|
+
|
534
|
+
/** ZSTD_rollingHash_primePower() :
|
535
|
+
* Compute the primePower to be passed to ZSTD_rollingHash_rotate() for a hash
|
536
|
+
* over a window of length bytes.
|
537
|
+
*/
|
538
|
+
MEM_STATIC U64 ZSTD_rollingHash_primePower(U32 length)
|
539
|
+
{
|
540
|
+
return ZSTD_ipow(prime8bytes, length - 1);
|
541
|
+
}
|
542
|
+
|
543
|
+
/** ZSTD_rollingHash_rotate() :
|
544
|
+
* Rotate the rolling hash by one byte.
|
545
|
+
*/
|
546
|
+
MEM_STATIC U64 ZSTD_rollingHash_rotate(U64 hash, BYTE toRemove, BYTE toAdd, U64 primePower)
|
547
|
+
{
|
548
|
+
hash -= (toRemove + ZSTD_ROLL_HASH_CHAR_OFFSET) * primePower;
|
549
|
+
hash *= prime8bytes;
|
550
|
+
hash += toAdd + ZSTD_ROLL_HASH_CHAR_OFFSET;
|
551
|
+
return hash;
|
552
|
+
}
|
553
|
+
|
501
554
|
/*-*************************************
|
502
555
|
* Round buffer management
|
503
556
|
***************************************/
|
@@ -626,20 +679,23 @@ MEM_STATIC U32 ZSTD_window_correctOverflow(ZSTD_window_t* window, U32 cycleLog,
|
|
626
679
|
* dictMatchState mode, lowLimit and dictLimit are the same, and the dictionary
|
627
680
|
* is below them. forceWindow and dictMatchState are therefore incompatible.
|
628
681
|
*/
|
629
|
-
MEM_STATIC void
|
630
|
-
|
631
|
-
|
632
|
-
|
682
|
+
MEM_STATIC void
|
683
|
+
ZSTD_window_enforceMaxDist(ZSTD_window_t* window,
|
684
|
+
void const* srcEnd,
|
685
|
+
U32 maxDist,
|
686
|
+
U32* loadedDictEndPtr,
|
687
|
+
const ZSTD_matchState_t** dictMatchStatePtr)
|
633
688
|
{
|
634
|
-
U32 const
|
635
|
-
U32 loadedDictEnd = loadedDictEndPtr != NULL ? *loadedDictEndPtr : 0;
|
636
|
-
DEBUGLOG(5, "ZSTD_window_enforceMaxDist:
|
637
|
-
|
638
|
-
|
689
|
+
U32 const blockEndIdx = (U32)((BYTE const*)srcEnd - window->base);
|
690
|
+
U32 loadedDictEnd = (loadedDictEndPtr != NULL) ? *loadedDictEndPtr : 0;
|
691
|
+
DEBUGLOG(5, "ZSTD_window_enforceMaxDist: blockEndIdx=%u, maxDist=%u",
|
692
|
+
(unsigned)blockEndIdx, (unsigned)maxDist);
|
693
|
+
if (blockEndIdx > maxDist + loadedDictEnd) {
|
694
|
+
U32 const newLowLimit = blockEndIdx - maxDist;
|
639
695
|
if (window->lowLimit < newLowLimit) window->lowLimit = newLowLimit;
|
640
696
|
if (window->dictLimit < window->lowLimit) {
|
641
697
|
DEBUGLOG(5, "Update dictLimit to match lowLimit, from %u to %u",
|
642
|
-
window->dictLimit, window->lowLimit);
|
698
|
+
(unsigned)window->dictLimit, (unsigned)window->lowLimit);
|
643
699
|
window->dictLimit = window->lowLimit;
|
644
700
|
}
|
645
701
|
if (loadedDictEndPtr)
|
@@ -690,20 +746,23 @@ MEM_STATIC U32 ZSTD_window_update(ZSTD_window_t* window,
|
|
690
746
|
|
691
747
|
|
692
748
|
/* debug functions */
|
749
|
+
#if (DEBUGLEVEL>=2)
|
693
750
|
|
694
751
|
MEM_STATIC double ZSTD_fWeight(U32 rawStat)
|
695
752
|
{
|
696
753
|
U32 const fp_accuracy = 8;
|
697
754
|
U32 const fp_multiplier = (1 << fp_accuracy);
|
698
|
-
U32 const
|
699
|
-
U32 const hb = ZSTD_highbit32(
|
755
|
+
U32 const newStat = rawStat + 1;
|
756
|
+
U32 const hb = ZSTD_highbit32(newStat);
|
700
757
|
U32 const BWeight = hb * fp_multiplier;
|
701
|
-
U32 const FWeight = (
|
758
|
+
U32 const FWeight = (newStat << fp_accuracy) >> hb;
|
702
759
|
U32 const weight = BWeight + FWeight;
|
703
760
|
assert(hb + fp_accuracy < 31);
|
704
761
|
return (double)weight / fp_multiplier;
|
705
762
|
}
|
706
763
|
|
764
|
+
/* display a table content,
|
765
|
+
* listing each element, its frequency, and its predicted bit cost */
|
707
766
|
MEM_STATIC void ZSTD_debugTable(const U32* table, U32 max)
|
708
767
|
{
|
709
768
|
unsigned u, sum;
|
@@ -715,6 +774,9 @@ MEM_STATIC void ZSTD_debugTable(const U32* table, U32 max)
|
|
715
774
|
}
|
716
775
|
}
|
717
776
|
|
777
|
+
#endif
|
778
|
+
|
779
|
+
|
718
780
|
#if defined (__cplusplus)
|
719
781
|
}
|
720
782
|
#endif
|
@@ -18,7 +18,7 @@ void ZSTD_fillDoubleHashTable(ZSTD_matchState_t* ms,
|
|
18
18
|
const ZSTD_compressionParameters* const cParams = &ms->cParams;
|
19
19
|
U32* const hashLarge = ms->hashTable;
|
20
20
|
U32 const hBitsL = cParams->hashLog;
|
21
|
-
U32 const mls = cParams->
|
21
|
+
U32 const mls = cParams->minMatch;
|
22
22
|
U32* const hashSmall = ms->chainTable;
|
23
23
|
U32 const hBitsS = cParams->chainLog;
|
24
24
|
const BYTE* const base = ms->window.base;
|
@@ -309,7 +309,7 @@ size_t ZSTD_compressBlock_doubleFast(
|
|
309
309
|
ZSTD_matchState_t* ms, seqStore_t* seqStore, U32 rep[ZSTD_REP_NUM],
|
310
310
|
void const* src, size_t srcSize)
|
311
311
|
{
|
312
|
-
const U32 mls = ms->cParams.
|
312
|
+
const U32 mls = ms->cParams.minMatch;
|
313
313
|
switch(mls)
|
314
314
|
{
|
315
315
|
default: /* includes case 3 */
|
@@ -329,7 +329,7 @@ size_t ZSTD_compressBlock_doubleFast_dictMatchState(
|
|
329
329
|
ZSTD_matchState_t* ms, seqStore_t* seqStore, U32 rep[ZSTD_REP_NUM],
|
330
330
|
void const* src, size_t srcSize)
|
331
331
|
{
|
332
|
-
const U32 mls = ms->cParams.
|
332
|
+
const U32 mls = ms->cParams.minMatch;
|
333
333
|
switch(mls)
|
334
334
|
{
|
335
335
|
default: /* includes case 3 */
|
@@ -483,7 +483,7 @@ size_t ZSTD_compressBlock_doubleFast_extDict(
|
|
483
483
|
ZSTD_matchState_t* ms, seqStore_t* seqStore, U32 rep[ZSTD_REP_NUM],
|
484
484
|
void const* src, size_t srcSize)
|
485
485
|
{
|
486
|
-
U32 const mls = ms->cParams.
|
486
|
+
U32 const mls = ms->cParams.minMatch;
|
487
487
|
switch(mls)
|
488
488
|
{
|
489
489
|
default: /* includes case 3 */
|
@@ -18,7 +18,7 @@ void ZSTD_fillHashTable(ZSTD_matchState_t* ms,
|
|
18
18
|
const ZSTD_compressionParameters* const cParams = &ms->cParams;
|
19
19
|
U32* const hashTable = ms->hashTable;
|
20
20
|
U32 const hBits = cParams->hashLog;
|
21
|
-
U32 const mls = cParams->
|
21
|
+
U32 const mls = cParams->minMatch;
|
22
22
|
const BYTE* const base = ms->window.base;
|
23
23
|
const BYTE* ip = base + ms->nextToUpdate;
|
24
24
|
const BYTE* const iend = ((const BYTE*)end) - HASH_READ_SIZE;
|
@@ -27,18 +27,18 @@ void ZSTD_fillHashTable(ZSTD_matchState_t* ms,
|
|
27
27
|
/* Always insert every fastHashFillStep position into the hash table.
|
28
28
|
* Insert the other positions if their hash entry is empty.
|
29
29
|
*/
|
30
|
-
for (; ip + fastHashFillStep
|
30
|
+
for ( ; ip + fastHashFillStep < iend + 2; ip += fastHashFillStep) {
|
31
31
|
U32 const current = (U32)(ip - base);
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
}
|
32
|
+
size_t const hash0 = ZSTD_hashPtr(ip, hBits, mls);
|
33
|
+
hashTable[hash0] = current;
|
34
|
+
if (dtlm == ZSTD_dtlm_fast) continue;
|
35
|
+
/* Only load extra positions for ZSTD_dtlm_full */
|
36
|
+
{ U32 p;
|
37
|
+
for (p = 1; p < fastHashFillStep; ++p) {
|
38
|
+
size_t const hash = ZSTD_hashPtr(ip + p, hBits, mls);
|
39
|
+
if (hashTable[hash] == 0) { /* not yet filled */
|
40
|
+
hashTable[hash] = current + p;
|
41
|
+
} } } }
|
42
42
|
}
|
43
43
|
|
44
44
|
FORCE_INLINE_TEMPLATE
|
@@ -235,7 +235,7 @@ size_t ZSTD_compressBlock_fast(
|
|
235
235
|
void const* src, size_t srcSize)
|
236
236
|
{
|
237
237
|
ZSTD_compressionParameters const* cParams = &ms->cParams;
|
238
|
-
U32 const mls = cParams->
|
238
|
+
U32 const mls = cParams->minMatch;
|
239
239
|
assert(ms->dictMatchState == NULL);
|
240
240
|
switch(mls)
|
241
241
|
{
|
@@ -256,7 +256,7 @@ size_t ZSTD_compressBlock_fast_dictMatchState(
|
|
256
256
|
void const* src, size_t srcSize)
|
257
257
|
{
|
258
258
|
ZSTD_compressionParameters const* cParams = &ms->cParams;
|
259
|
-
U32 const mls = cParams->
|
259
|
+
U32 const mls = cParams->minMatch;
|
260
260
|
assert(ms->dictMatchState != NULL);
|
261
261
|
switch(mls)
|
262
262
|
{
|
@@ -375,7 +375,7 @@ size_t ZSTD_compressBlock_fast_extDict(
|
|
375
375
|
void const* src, size_t srcSize)
|
376
376
|
{
|
377
377
|
ZSTD_compressionParameters const* cParams = &ms->cParams;
|
378
|
-
U32 const mls = cParams->
|
378
|
+
U32 const mls = cParams->minMatch;
|
379
379
|
switch(mls)
|
380
380
|
{
|
381
381
|
default: /* includes case 3 */
|
@@ -63,12 +63,13 @@ ZSTD_updateDUBT(ZSTD_matchState_t* ms,
|
|
63
63
|
static void
|
64
64
|
ZSTD_insertDUBT1(ZSTD_matchState_t* ms,
|
65
65
|
U32 current, const BYTE* inputEnd,
|
66
|
-
U32 nbCompares, U32 btLow,
|
66
|
+
U32 nbCompares, U32 btLow,
|
67
|
+
const ZSTD_dictMode_e dictMode)
|
67
68
|
{
|
68
69
|
const ZSTD_compressionParameters* const cParams = &ms->cParams;
|
69
|
-
U32*
|
70
|
-
U32
|
71
|
-
U32
|
70
|
+
U32* const bt = ms->chainTable;
|
71
|
+
U32 const btLog = cParams->chainLog - 1;
|
72
|
+
U32 const btMask = (1 << btLog) - 1;
|
72
73
|
size_t commonLengthSmaller=0, commonLengthLarger=0;
|
73
74
|
const BYTE* const base = ms->window.base;
|
74
75
|
const BYTE* const dictBase = ms->window.dictBase;
|
@@ -80,7 +81,7 @@ ZSTD_insertDUBT1(ZSTD_matchState_t* ms,
|
|
80
81
|
const BYTE* match;
|
81
82
|
U32* smallerPtr = bt + 2*(current&btMask);
|
82
83
|
U32* largerPtr = smallerPtr + 1;
|
83
|
-
U32 matchIndex = *smallerPtr;
|
84
|
+
U32 matchIndex = *smallerPtr; /* this candidate is unsorted : next sorted candidate is reached through *smallerPtr, while *largerPtr contains previous unsorted candidate (which is already saved and can be overwritten) */
|
84
85
|
U32 dummy32; /* to be nullified at the end */
|
85
86
|
U32 const windowLow = ms->window.lowLimit;
|
86
87
|
|
@@ -93,6 +94,9 @@ ZSTD_insertDUBT1(ZSTD_matchState_t* ms,
|
|
93
94
|
U32* const nextPtr = bt + 2*(matchIndex & btMask);
|
94
95
|
size_t matchLength = MIN(commonLengthSmaller, commonLengthLarger); /* guaranteed minimum nb of common bytes */
|
95
96
|
assert(matchIndex < current);
|
97
|
+
/* note : all candidates are now supposed sorted,
|
98
|
+
* but it's still possible to have nextPtr[1] == ZSTD_DUBT_UNSORTED_MARK
|
99
|
+
* when a real index has the same value as ZSTD_DUBT_UNSORTED_MARK */
|
96
100
|
|
97
101
|
if ( (dictMode != ZSTD_extDict)
|
98
102
|
|| (matchIndex+matchLength >= dictLimit) /* both in current segment*/
|
@@ -108,7 +112,7 @@ ZSTD_insertDUBT1(ZSTD_matchState_t* ms,
|
|
108
112
|
match = dictBase + matchIndex;
|
109
113
|
matchLength += ZSTD_count_2segments(ip+matchLength, match+matchLength, iend, dictEnd, prefixStart);
|
110
114
|
if (matchIndex+matchLength >= dictLimit)
|
111
|
-
match = base + matchIndex; /*
|
115
|
+
match = base + matchIndex; /* preparation for next read of match[matchLength] */
|
112
116
|
}
|
113
117
|
|
114
118
|
DEBUGLOG(8, "ZSTD_insertDUBT1: comparing %u with %u : found %u common bytes ",
|
@@ -258,7 +262,7 @@ ZSTD_DUBT_findBestMatch(ZSTD_matchState_t* ms,
|
|
258
262
|
&& (nbCandidates > 1) ) {
|
259
263
|
DEBUGLOG(8, "ZSTD_DUBT_findBestMatch: candidate %u is unsorted",
|
260
264
|
matchIndex);
|
261
|
-
*unsortedMark = previousCandidate;
|
265
|
+
*unsortedMark = previousCandidate; /* the unsortedMark becomes a reversed chain, to move up back to original position */
|
262
266
|
previousCandidate = matchIndex;
|
263
267
|
matchIndex = *nextCandidate;
|
264
268
|
nextCandidate = bt + 2*(matchIndex&btMask);
|
@@ -266,11 +270,13 @@ ZSTD_DUBT_findBestMatch(ZSTD_matchState_t* ms,
|
|
266
270
|
nbCandidates --;
|
267
271
|
}
|
268
272
|
|
273
|
+
/* nullify last candidate if it's still unsorted
|
274
|
+
* simplification, detrimental to compression ratio, beneficial for speed */
|
269
275
|
if ( (matchIndex > unsortLimit)
|
270
276
|
&& (*unsortedMark==ZSTD_DUBT_UNSORTED_MARK) ) {
|
271
277
|
DEBUGLOG(7, "ZSTD_DUBT_findBestMatch: nullify last unsorted candidate %u",
|
272
278
|
matchIndex);
|
273
|
-
*nextCandidate = *unsortedMark = 0;
|
279
|
+
*nextCandidate = *unsortedMark = 0;
|
274
280
|
}
|
275
281
|
|
276
282
|
/* batch sort stacked candidates */
|
@@ -285,14 +291,14 @@ ZSTD_DUBT_findBestMatch(ZSTD_matchState_t* ms,
|
|
285
291
|
}
|
286
292
|
|
287
293
|
/* find longest match */
|
288
|
-
{ size_t commonLengthSmaller=0, commonLengthLarger=0;
|
294
|
+
{ size_t commonLengthSmaller = 0, commonLengthLarger = 0;
|
289
295
|
const BYTE* const dictBase = ms->window.dictBase;
|
290
296
|
const U32 dictLimit = ms->window.dictLimit;
|
291
297
|
const BYTE* const dictEnd = dictBase + dictLimit;
|
292
298
|
const BYTE* const prefixStart = base + dictLimit;
|
293
299
|
U32* smallerPtr = bt + 2*(current&btMask);
|
294
300
|
U32* largerPtr = bt + 2*(current&btMask) + 1;
|
295
|
-
U32 matchEndIdx = current+8+1;
|
301
|
+
U32 matchEndIdx = current + 8 + 1;
|
296
302
|
U32 dummy32; /* to be nullified at the end */
|
297
303
|
size_t bestLength = 0;
|
298
304
|
|
@@ -386,7 +392,7 @@ ZSTD_BtFindBestMatch_selectMLS ( ZSTD_matchState_t* ms,
|
|
386
392
|
const BYTE* ip, const BYTE* const iLimit,
|
387
393
|
size_t* offsetPtr)
|
388
394
|
{
|
389
|
-
switch(ms->cParams.
|
395
|
+
switch(ms->cParams.minMatch)
|
390
396
|
{
|
391
397
|
default : /* includes case 3 */
|
392
398
|
case 4 : return ZSTD_BtFindBestMatch(ms, ip, iLimit, offsetPtr, 4, ZSTD_noDict);
|
@@ -402,7 +408,7 @@ static size_t ZSTD_BtFindBestMatch_dictMatchState_selectMLS (
|
|
402
408
|
const BYTE* ip, const BYTE* const iLimit,
|
403
409
|
size_t* offsetPtr)
|
404
410
|
{
|
405
|
-
switch(ms->cParams.
|
411
|
+
switch(ms->cParams.minMatch)
|
406
412
|
{
|
407
413
|
default : /* includes case 3 */
|
408
414
|
case 4 : return ZSTD_BtFindBestMatch(ms, ip, iLimit, offsetPtr, 4, ZSTD_dictMatchState);
|
@@ -418,7 +424,7 @@ static size_t ZSTD_BtFindBestMatch_extDict_selectMLS (
|
|
418
424
|
const BYTE* ip, const BYTE* const iLimit,
|
419
425
|
size_t* offsetPtr)
|
420
426
|
{
|
421
|
-
switch(ms->cParams.
|
427
|
+
switch(ms->cParams.minMatch)
|
422
428
|
{
|
423
429
|
default : /* includes case 3 */
|
424
430
|
case 4 : return ZSTD_BtFindBestMatch(ms, ip, iLimit, offsetPtr, 4, ZSTD_extDict);
|
@@ -433,7 +439,7 @@ static size_t ZSTD_BtFindBestMatch_extDict_selectMLS (
|
|
433
439
|
/* *********************************
|
434
440
|
* Hash Chain
|
435
441
|
***********************************/
|
436
|
-
#define NEXT_IN_CHAIN(d, mask) chainTable[(d) & mask]
|
442
|
+
#define NEXT_IN_CHAIN(d, mask) chainTable[(d) & (mask)]
|
437
443
|
|
438
444
|
/* Update chains up to ip (excluded)
|
439
445
|
Assumption : always within prefix (i.e. not within extDict) */
|
@@ -463,7 +469,7 @@ static U32 ZSTD_insertAndFindFirstIndex_internal(
|
|
463
469
|
|
464
470
|
U32 ZSTD_insertAndFindFirstIndex(ZSTD_matchState_t* ms, const BYTE* ip) {
|
465
471
|
const ZSTD_compressionParameters* const cParams = &ms->cParams;
|
466
|
-
return ZSTD_insertAndFindFirstIndex_internal(ms, cParams, ip, ms->cParams.
|
472
|
+
return ZSTD_insertAndFindFirstIndex_internal(ms, cParams, ip, ms->cParams.minMatch);
|
467
473
|
}
|
468
474
|
|
469
475
|
|
@@ -497,6 +503,7 @@ size_t ZSTD_HcFindBestMatch_generic (
|
|
497
503
|
size_t currentMl=0;
|
498
504
|
if ((dictMode != ZSTD_extDict) || matchIndex >= dictLimit) {
|
499
505
|
const BYTE* const match = base + matchIndex;
|
506
|
+
assert(matchIndex >= dictLimit); /* ensures this is true if dictMode != ZSTD_extDict */
|
500
507
|
if (match[ml] == ip[ml]) /* potentially better */
|
501
508
|
currentMl = ZSTD_count(ip, match, iLimit);
|
502
509
|
} else {
|
@@ -559,7 +566,7 @@ FORCE_INLINE_TEMPLATE size_t ZSTD_HcFindBestMatch_selectMLS (
|
|
559
566
|
const BYTE* ip, const BYTE* const iLimit,
|
560
567
|
size_t* offsetPtr)
|
561
568
|
{
|
562
|
-
switch(ms->cParams.
|
569
|
+
switch(ms->cParams.minMatch)
|
563
570
|
{
|
564
571
|
default : /* includes case 3 */
|
565
572
|
case 4 : return ZSTD_HcFindBestMatch_generic(ms, ip, iLimit, offsetPtr, 4, ZSTD_noDict);
|
@@ -575,7 +582,7 @@ static size_t ZSTD_HcFindBestMatch_dictMatchState_selectMLS (
|
|
575
582
|
const BYTE* ip, const BYTE* const iLimit,
|
576
583
|
size_t* offsetPtr)
|
577
584
|
{
|
578
|
-
switch(ms->cParams.
|
585
|
+
switch(ms->cParams.minMatch)
|
579
586
|
{
|
580
587
|
default : /* includes case 3 */
|
581
588
|
case 4 : return ZSTD_HcFindBestMatch_generic(ms, ip, iLimit, offsetPtr, 4, ZSTD_dictMatchState);
|
@@ -591,7 +598,7 @@ FORCE_INLINE_TEMPLATE size_t ZSTD_HcFindBestMatch_extDict_selectMLS (
|
|
591
598
|
const BYTE* ip, const BYTE* const iLimit,
|
592
599
|
size_t* offsetPtr)
|
593
600
|
{
|
594
|
-
switch(ms->cParams.
|
601
|
+
switch(ms->cParams.minMatch)
|
595
602
|
{
|
596
603
|
default : /* includes case 3 */
|
597
604
|
case 4 : return ZSTD_HcFindBestMatch_generic(ms, ip, iLimit, offsetPtr, 4, ZSTD_extDict);
|